Skip to content

Commit

Permalink
修复生成节气错误 (#84)
Browse files Browse the repository at this point in the history
Co-authored-by: yaoqiankun <yaoqiankun@datarc.cn>
  • Loading branch information
yqkcn and yaoqiankun authored Apr 9, 2022
1 parent 4872c20 commit 111e92f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion chinese_calendar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ def get_solar_terms(start, end):
delta = SOLAR_TERMS_DELTA.get((year, solar_term))
if delta:
day += delta
result.append((datetime.date(year, month, day), solar_term.value[1]))
_date = datetime.date(year, month, day)
if _date < start or _date > end:
continue
result.append((_date, solar_term.value[1]))
if month == 12:
year, month = year + 1, 1
else:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_solar_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,9 @@ def test_get_solar_terms(self):
(datetime.date(2023, 12, 22), "冬至"),
]
self.assertEqual(expected, actual)

start = datetime.date(2023, 1, 6)
end = datetime.date(2023, 1, 19)
actual = chinese_calendar.get_solar_terms(start, end)
expected = []
self.assertEqual(expected, actual)

0 comments on commit 111e92f

Please sign in to comment.