Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/convertdate/indian_civil.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def to_gregorian(year, month, day):


def month_length(year, month):
if month in HAVE_31_DAYS or (month == 1 and isleap(year - SAKA_EPOCH)):
if month in HAVE_31_DAYS or (month == 1 and isleap(year + SAKA_EPOCH)):
return 31
return 30

Expand Down
8 changes: 8 additions & 0 deletions tests/test_indian_civil.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ def test_month_length_indian_civil(self):
self.assertEqual(indian_civil.month_length(1922, 1), 31)
self.assertEqual(indian_civil.month_length(1923, 1), 30)

def test_chaitra_century_leap_years(self):
for year, expected in [(1822, 30), (1878, 31), (1922, 31), (1978, 31), (2022, 30)]:
with self.subTest(year=year):
self.assertEqual(indian_civil.month_length(year, 1), expected)
days = [day for week in indian_civil.monthcalendar(year, 1) for day in week if day is not None]
self.assertEqual(days, list(range(1, expected + 1)))
self.assertEqual(indian_civil.to_jd(year, 2, 1) - indian_civil.to_jd(year, 1, 1), expected)

def test_monthcalendar_indian_civil(self):
self.assertEqual(indian_civil.monthcalendar(1936, 8).pop(0).pop(4), 1)
self.assertEqual(indian_civil.monthcalendar(1927, 2).pop(0).pop(4), 1)
Expand Down