private Period(
     TwoThousandsCommonEraYear startYear,
     TwoThousandsCommonEraYear endYear)
 {
     EndYear   = endYear;
     StartYear = startYear;
 }
Esempio n. 2
0
 public void Can_Be_Created_From_Integer_Year(
     int year)
 {
     TwoThousandsCommonEraYear
     .FromYearAsNumber(year)
     .Should()
     .NotBeNull();
 }
Esempio n. 3
0
 public void Has_Expected_AsTwoDigitString_Property(
     string twoDigitYear)
 {
     TwoThousandsCommonEraYear
     .ParseTwoDigitYear(twoDigitYear)
     .AsTwoDigitString
     .Should()
     .Be(twoDigitYear);
 }
Esempio n. 4
0
 public void Parses_Correctly_From_Two_Digit_Year(
     string twoDigitYear,
     int expectedParsedYear)
 {
     TwoThousandsCommonEraYear
     .ParseTwoDigitYear(twoDigitYear)
     .AsInt
     .Should()
     .Be(expectedParsedYear);
 }
Esempio n. 5
0
 public void Throws_Exception_When_Trying_To_Create_From_Invalid_Integer_Year(
     int invalidYear)
 {
     Assert
     .That(
         () => TwoThousandsCommonEraYear.FromYearAsNumber(invalidYear),
         Throws
         .Exception
         .TypeOf <ArgumentException>());
 }
Esempio n. 6
0
 public void Throws_ArgumentException_When_Asked_To_Parse_Invalid_Two_Digit_Year(
     string invalidTwoDigitYear)
 {
     Assert
     .That(
         () => TwoThousandsCommonEraYear.ParseTwoDigitYear(invalidTwoDigitYear),
         Throws
         .Exception
         .TypeOf <ArgumentException>());
 }
        public static Period FromInstantInPeriod(DateTime instantInPeriod)
        {
            var endYear =
                instantInPeriod.Month < 4
                    ? instantInPeriod.Year - 1
                    : instantInPeriod.Year;

            return(new Period(
                       startYear: TwoThousandsCommonEraYear.FromYearAsNumber(endYear - 1),
                       endYear: TwoThousandsCommonEraYear.FromYearAsNumber(endYear)));
        }
Esempio n. 8
0
        public void Is_Equatable_With_Another_TwoThousandsCommonEraYear(
            string left,
            string right,
            bool expectedEqual)
        {
            var leftYear =
                TwoThousandsCommonEraYear
                .ParseTwoDigitYear(left);

            var rightYear =
                TwoThousandsCommonEraYear
                .ParseTwoDigitYear(right);

            leftYear
            .Equals(rightYear)
            .Should()
            .Be(expectedEqual);
        }
        public static Period ParsePeriodString(string periodString)
        {
            if (string.IsNullOrWhiteSpace(periodString))
            {
                throw new ArgumentException($"{periodString} cannot be parsed; should be 4 chars e.g. 1516 to represent period 2015/2016", nameof(periodString));
            }

            if (periodString.Length != 4)
            {
                throw new ArgumentException($"{periodString} cannot be parsed; should be 4 chars e.g. 1516 to represent period 2015/2016", nameof(periodString));
            }

            return(new Period(
                       startYear:
                       TwoThousandsCommonEraYear
                       .ParseTwoDigitYear(periodString.Substring(0, 2)),
                       endYear:
                       TwoThousandsCommonEraYear
                       .ParseTwoDigitYear(periodString.Substring(2, 2))));
        }