leap year fixes in date properties
This commit is contained in:
parent
08c74c36e5
commit
b7404f7741
@ -79,6 +79,8 @@ class FixedDate:
|
||||
"""In range 1...29"""
|
||||
if self.is_leap_day:
|
||||
return 29
|
||||
if self.is_leap_year and self.day_of_year > 169: # leap day past this year
|
||||
return ((self._day_of_year-2) % 28) + 1
|
||||
return ((self._day_of_year-1) % 28) + 1
|
||||
|
||||
@property
|
||||
|
@ -34,6 +34,18 @@ class TestLeapYear(unittest.TestCase):
|
||||
self.assertEqual(fixed_date.week_of_year, 24)
|
||||
self.assertEqual(fixed_date.year_quarter, 2)
|
||||
|
||||
def test_year_day_of_leap_year(self):
|
||||
fixed_date = FixedDate(day_of_year=366, year=2024)
|
||||
self.assertTrue(fixed_date.is_year_day)
|
||||
self.assertEqual(fixed_date.year, 2024)
|
||||
self.assertEqual(fixed_date.month, 14)
|
||||
self.assertEqual(fixed_date.day_of_month, 1)
|
||||
|
||||
def test_ordinary_date_after_leap_day(self):
|
||||
fixed_date = FixedDate(datetime(2024, 10, 13))
|
||||
self.assertEqual(fixed_date.month, 11)
|
||||
self.assertEqual(fixed_date.day_of_month, 6)
|
||||
|
||||
|
||||
def test_fixed_date_difference_over_gregorian_leap_day(self):
|
||||
# in Gregorian system there are 7 days between,
|
||||
|
Loading…
x
Reference in New Issue
Block a user