Skip to content

fix(lunar): don't report festivals on leap month days - #405

Merged
gouguoyin merged 1 commit into
dromara:masterfrom
bardrop-oss:fix-lunar-festival-leap-month
Nov 20, 2026
Merged

gouguoyin merged 1 commit into
dromara:masterfrom
bardrop-oss:fix-lunar-festival-leap-month

Conversation

@bardrop

@bardrop bardrop commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Lunar.Festival() looks up only month-day, so in a year whose leap month has the same number as a festival month, the festival is reported twice: once in the regular month and again in the leap month.

carbon.Parse("1995-10-09", "PRC").Lunar().Festival() // "中秋节", but this is 闰八月十五; 中秋节 1995 was 1995-09-09
carbon.Parse("2023-03-23", "PRC").Lunar().Festival() // "龙抬头", but this is 闰二月初二; 龙抬头 2023 was 2023-02-21
carbon.Parse("2028-06-27", "PRC").Lunar().Festival() // "端午节", but this is 闰五月初五; 端午节 2028 is 2028-05-28

Between 1990 and 2040 this hits 15 days (端午节 in 1990, 1998, 2009, 2028, 2039; 七夕节 + 中元节 in 2006, ...). Traditional festivals are kept in the regular month only.

Change

Festival() returns "" when isLeapMonth is true. Regular months are unchanged.

Tests

New leap month subtest in TestLunar_Festival: the regular-month day still has the festival, the leap-month day with the same number has none (2023 闰二月, 1995 闰八月, 2006 闰七月, 2028 闰五月, plus NewLunar(2023, 2, 2, true)). The leap-month asserts fail on master and pass here. go test -race ./..., go vet ./... and gofmt are clean.

This doesn't touch the lunar data table, so it doesn't conflict with #404.

Festival() looked up month-day only, so a leap month with the same number
as a festival month got the festival a second time (闰五月初五 → 端午节).
Festivals are in the regular month only.
@gouguoyin
gouguoyin merged commit 8d20495 into dromara:master Nov 20, 2026
7 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.

2 participants