Skip to content

Commit

Permalink
fix a bug in LunarDate(1899, 1, 1).toSolarDate(), it should raise an …
Browse files Browse the repository at this point in the history
…exception
  • Loading branch information
lidaobing committed Dec 7, 2023
1 parent dde32a2 commit 2e93d78
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lunardate.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ def toSolarDate(self):
datetime.date(2008, 10, 2)
>>> LunarDate(1976, 8, 8, 1).toSolarDate()
datetime.date(1976, 10, 1)
>>> LunarDate(1976, 7, 8, 1).toSolarDate()
Traceback (most recent call last):
...
ValueError: month out of range
>>> LunarDate(1899, 1, 1).toSolarDate()
Traceback (most recent call last):
...
ValueError: year out of range [1900, 2100)
>>> LunarDate(2004, 1, 30).toSolarDate()
Traceback (most recent call last):
...
Expand Down Expand Up @@ -183,9 +191,9 @@ def _calcDays(yearInfo, month, day, isLeapMonth):
offset = 0
start_year = 1900
end_year = start_year + len(yearInfos)
if start_year < 1900 or self.year >= end_year:
if self.year < start_year or self.year >= end_year:
raise ValueError('year out of range [{}, {})'.format(start_year, end_year))
yearIdx = self.year - 1900
yearIdx = self.year - start_year
for i in range(yearIdx):
offset += yearDays[i]

Expand Down

0 comments on commit 2e93d78

Please sign in to comment.