Skip to content

Fix month lengths for lunar years 1933, 1954 and 1978 - #25

Merged
lidaobing merged 1 commit into
lidaobing:masterfrom
bardrop-oss:fix-1933-1954-1978-month-lengths
Nov 22, 2026
Merged

lidaobing merged 1 commit into
lidaobing:masterfrom
bardrop-oss:fix-1933-1954-1978-month-lengths

Conversation

@bardrop

@bardrop bardrop commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Three entries in yearInfos don't match the Hong Kong Observatory conversion tables, so 30 days in each of these years come out one day off:

>>> LunarDate.from_solar_date(1954, 11, 25)
LunarDate(1954, 10, 30, 0)   # HKO: first day of the 11th month
>>> LunarDate.from_solar_date(1978, 9, 2)
LunarDate(1978, 8, 1, 0)     # HKO: 7th month, day 30 (8th month starts 1978-09-03)
>>> LunarDate.from_solar_date(1933, 7, 22)
LunarDate(1933, 6, 1, 0)     # HKO: leap 5th month, day 30 (6th month starts 1933-07-23)
year now fixed what changes
1933 0x06e95 0x16a95 leap 5th month is long (30 days), 6th month is short (29)
1954 0x0a5d0 0x0a5b0 10th month has 29 days, not 30
1978 0x0b5a0 0x0b6a0 7th month has 30 days, 8th month 29

The year lengths don't change, so nothing outside those 30-day windows moves. The fixed values are the same ones used in other tables (e.g. calendar.js and overtrue/chinese-calendar).

How I checked: compared every day from 1901 to 2099 (72,684 days, plus every month start and leap month) against the HKO tables (https://www.hko.gov.hk/en/gts/time/calendar/text/files/T1954e.txt etc.). Before this change, only these three years differ; after it, none do.

Added doctests for the three years (5 of them fail before the fix). python lunardate.py -v passes, mypy lunardate.py and the CI flake8 check are clean.

Three entries in yearInfos disagree with the Hong Kong Observatory
conversion tables, so 30 days in each of those years are converted one
day off:

- 1933: the leap 5th month has 30 days and the 6th month 29
  (0x06e95 -> 0x16a95; HKO: 6th month starts 1933-07-23)
- 1954: the 10th month has 29 days (0x0a5d0 -> 0x0a5b0; HKO: 11th
  month starts 1954-11-25)
- 1978: the 7th month has 30 days and the 8th month 29
  (0x0b5a0 -> 0x0b6a0; HKO: 8th month starts 1978-09-03)

With these, every day from 1901 to 2099 matches the HKO tables.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the lunar month-length corrections and accompanying regression doctests.

No open issues 🎉

What changed in this PR

Corrects lunar month-length data for 1933, 1954, and 1978 to align date conversions with the Hong Kong Observatory tables.

Changes:

  • Updates three yearInfos entries while preserving total year lengths.
  • Adds five doctests covering affected dates, including leap-month and month-start boundaries.
File Description
lunardate.py Corrects the three year entries and adds regression doctests for solar/lunar conversions.

Review effort: Balanced

@lidaobing
lidaobing merged commit dd8a3cd into lidaobing:master Nov 22, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants