예제 #1
0
        // Convert string line from the input file
        // into InputDataModel with checking ObservationDate and Shorthand.
        // If ObservationDate not present
        // or Shorthand not present and cannot be restored
        // then return null to skip this line from further processing
        private static InputDataModel ConvertLine(string line)
        {
            var items = line.Split(',');

            // Skip not formerly formatted line
            if (items.Length != 5)
            {
                return(null);
            }

            var rawObservationDate = items[0];
            var rawShorthand       = items[1];
            var rawFrom            = items[2];
            var rawTo    = items[3];
            var rawPrice = items[4];

            var observationDate = rawObservationDate.ToDate();

            // There is no way to get observationDate from another data
            if (observationDate == null)
            {
                return(null);
            }

            var shorthand = new Quarter(rawShorthand);

            // Try to get shorthand from To or From date
            if (!shorthand.IsValid)
            {
                var from      = rawFrom.ToDate();
                var to        = rawTo.ToDate();
                var dateToTry = from ?? to;
                if (dateToTry == null)
                {
                    return(null);
                }

                shorthand = Quarter.FromDate(dateToTry.Value);
                // Skip line if not valid
                if (!shorthand.IsValid)
                {
                    return(null);
                }
            }

            // Uses null to leave missed price empty
            decimal?price = null;

            if (decimal.TryParse(rawPrice, out decimal parsedPrice))
            {
                price = parsedPrice;
            }

            return(new InputDataModel
            {
                ObservationDate = observationDate.Value,
                Shorthand = shorthand,
                Price = price
            });
        }
예제 #2
0
        public string FromDateShorthandTest(int year, int month, int day)
        {
            var date = new DateTime(year, month, day);

            return(Quarter.FromDate(date).ToString());
        }
예제 #3
0
        public void FromDateIsValidTest(int year, int month, int day)
        {
            var date = new DateTime(year, month, day);

            Assert.True(Quarter.FromDate(date).IsValid);
        }