Exemplo n.º 1
0
 def setUp(self):
     self.gregorian = ProlepticGregorianCalendar()
     self.julian = JulianCalendar()
     self.addTypeEqualityFunc(
         DateWithCalendar,
         DateWithCalendar.make_assertEqual(self)
     )
Exemplo n.º 2
0
 def setUp(self):
     self.calendar = JulianCalendar()
     self.setUpDateEquality()
Exemplo n.º 3
0
class TestJulianCalendar(CalendarTest):
    def setUp(self):
        self.calendar = JulianCalendar()
        self.setUpDateEquality()

    def test_display_string(self):
        """ The display string for a date gives the correct date and specifies the calendar. """
        d = self.calendar.date(1415, 10, 25)
        self.assertEqual(str(d), "25th October 1415 (Julian Calendar)")

    @given(datetimes(timezones=[]))
    @example(datetime(2100, 3, 1, 0, 0, 0))
    @example(datetime(4500, 4, 1, 0, 0, 0))
    @example(datetime(8200, 3, 1, 0, 0, 0))
    def test_make_julian_date_directly_and_via_year_month_day(self, dt):
        d = dt.date()
        julian_date_from_date = self.calendar.from_date(d)
        julian_representation = self.calendar.julian_representation(d)
        year, month, day = julian_representation
        julian_date_from_representation = self.calendar.date(year, month, day)
        self.calendar.bless(julian_date_from_representation)
        self.assertEqual(julian_date_from_date, julian_date_from_representation)

    def test_julian_number(self):
        d = self.calendar.date(1415, 10, 25)
        self.assertEqual(self.calendar.julian_day_number(d), 2238184)

    def test_julian_representation(self):
        d = date(8200, 3, 1)
        self.assertEqual(self.calendar.julian_representation(d), (8200, 1, 1))

    def test_making_a_tricky_date_correctly(self):
        julian_date = self.calendar.date(8200, 1, 1)
        self.assertEqual(julian_date.to_date(), date(8200, 3, 1))

    @given(datetimes(timezones=[]))
    @example(datetime(8200, 3, 1, 0, 0, 0))
    @example(datetime(8200, 2, 28, 0, 0, 0))
    @example(datetime(8199, 12, 31, 0, 0, 0))
    def test_julian_representation_round_trips_with_conversion(self, dt):
        d = dt.date()
        y, m, day = self.calendar.julian_representation(d)
        julian_date = self.calendar.date(y, m, day)
        self.assertEqual(julian_date.to_date(), d)
Exemplo n.º 4
0
class JulianGregorianConversion(unittest.TestCase):
    def setUp(self):
        self.gregorian = ProlepticGregorianCalendar()
        self.julian = JulianCalendar()
        self.addTypeEqualityFunc(
            DateWithCalendar,
            DateWithCalendar.make_assertEqual(self)
        )

    def Julian_to_Gregorian_conversion(self, julian_args, gregorian_args):
        julian_date = self.julian.date(*julian_args)
        gregorian_date = self.gregorian.date(*gregorian_args)
        converted_date = julian_date.convert_to(self.gregorian)
        self.assertEqual(
            converted_date,
            gregorian_date,
        )

    def Gregorian_to_Julian_conversion(self, julian_args, gregorian_args):
        gregorian_date = self.gregorian.date(*gregorian_args)
        julian_date = self.julian.date(*julian_args)
        converted_date = gregorian_date.convert_to(self.julian)
        self.assertEqual(
            converted_date,
            julian_date,
        )

    def check_both_conversions(self, julian_args, gregorian_args):
        self.Julian_to_Gregorian_conversion(julian_args, gregorian_args)
        self.Gregorian_to_Julian_conversion(julian_args, gregorian_args)

    def test_first_day_of_Gregorian_calendar(self):
        """ This date is the first day the Gregorian calendar was used
            in Catholic countries which adopted the new calendar immediately.
            We should be able to convert it from Julian to Gregorian."""
        self.check_both_conversions(
            (1582, 10, 5),
            (1582, 10, 15)
        )

    def test_a_Julian_only_leap_day(self):
        """ This date is a leap day of the Julian calendar.
            The corresponding day of the Gregorian calendar is not a leap day,
            and that year is not leap in the Gregorian calendar. """
        self.check_both_conversions(
            (1500, 2, 29),
            (1500, 3, 10)
        )

    def test_another_Julian_only_leap_day(self):
        """ This date is a leap day of the Julian calendar.
            The corresponding day of the Gregorian calendar is not a leap day,
            and that year is not leap in the Gregorian calendar. """
        self.check_both_conversions(
            (1400, 2, 29),
            (1400, 3, 9)
        )

    def test_the_day_before_a_Julian_only_leap_day(self):
        """ This date is Feb 28th before leap day of the Julian calendar.
            The corresponding day of the Gregorian calendar is not a leap day,
            and that year is not leap in the Gregorian calendar. """
        self.check_both_conversions(
            (1500, 2, 28),
            (1500, 3, 9)
        )

    def test_a_Gregorian_March_1st(self):
        """ This Gregorian date is March 1st, of a Julian-only leap year.
            Although the Julian date falls before the leap day,
            since the Gregorian date falls after it, the number of
            days difference between the dates in the two calendars
            depends which calendar you use to measure it. """
        self.check_both_conversions(
            (1500, 2, 20),
            (1500, 3, 1)
        )

    def test_a_Gregorian_Feb_28th(self):
        """ This Gregorian date is Feb 28th, of a Julian-only leap year.
            Both the Gregorian date, and the Julian date, are unaffected
            by the Julian leap day later in that year."""
        self.check_both_conversions(
            (1500, 2, 19),
            (1500, 2, 28)
        )

    def test_28th_Feb_8200(self):
        """This is a Julian-only leap year and Feb 28th and March 1st
           Gregorian fall in different years by the Julian calendar
           for the first time."""
        self.check_both_conversions(
            (8199, 12, 31),
            (8200, 2, 28)
        )

    def test_1st_March_8200(self):
        """This is a Julian-only leap year and Feb 28th Gregorian
           falls in a different Julian year for the first time."""
        self.check_both_conversions(
            (8200, 1, 1),
            (8200, 3, 1)
        )

    def test_1st_March_8300(self):
        """This is a Julian-only leap year and 1st March Gregorian
           falls in a different Julian year for the first time."""
        self.check_both_conversions(
            (8299, 12, 31),
            (8300, 3, 1)
        )