From 4e67ad4fa269df53ca68018a2da8e7570b057131 Mon Sep 17 00:00:00 2001 From: Anton Soloviev Date: Sat, 24 Oct 2026 18:30:19 -0700 Subject: [PATCH] Use the Gregorian year for Indian Civil month lengths --- src/convertdate/indian_civil.py | 2 +- tests/test_indian_civil.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/convertdate/indian_civil.py b/src/convertdate/indian_civil.py index 8f3c208..d15d9ec 100644 --- a/src/convertdate/indian_civil.py +++ b/src/convertdate/indian_civil.py @@ -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 diff --git a/tests/test_indian_civil.py b/tests/test_indian_civil.py index b6d68a1..6c57c16 100644 --- a/tests/test_indian_civil.py +++ b/tests/test_indian_civil.py @@ -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)