diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f722dd..eb3cebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -144,3 +144,7 @@ 1. Solar增加薪资比例; 2. 修正与寿星v5.10的节气误差; 3. 修复古时阴阳历转换错误的问题。 + +## 1.3.5 +1. 中元节改为农历七月十五; +2. 修复Solar的nextMonth超期问题。 diff --git a/lib/calendar/Solar.dart b/lib/calendar/Solar.dart index 5f03aab..20d9530 100644 --- a/lib/calendar/Solar.dart +++ b/lib/calendar/Solar.dart @@ -404,19 +404,17 @@ class Solar { int y = _year + years; int m = _month; int d = _day; - // 2月处理 - if (2 == m) { + if (1582 == y && 10 == m) { + if (d > 4 && d < 15) { + d += 10; + } + } else if (2 == m) { if (d > 28) { if (!SolarUtil.isLeapYear(y)) { d = 28; } } } - if (1582 == y && 10 == m) { - if (d > 4 && d < 15) { - d += 10; - } - } return Solar.fromYmdHms(y, m, d, _hour, _minute, _second); } @@ -425,18 +423,15 @@ class Solar { int y = month.getYear(); int m = month.getMonth(); int d = _day; - // 2月处理 - if (2 == m) { - if (d > 28) { - if (!SolarUtil.isLeapYear(y)) { - d = 28; - } - } - } if (1582 == y && 10 == m) { if (d > 4 && d < 15) { d += 10; } + } else { + int maxDay = SolarUtil.getDaysOfMonth(y, m); + if (d > maxDay) { + d = maxDay; + } } return Solar.fromYmdHms(y, m, d, _hour, _minute, _second); } diff --git a/lib/calendar/util/LunarUtil.dart b/lib/calendar/util/LunarUtil.dart index 6bceb19..83e4494 100644 --- a/lib/calendar/util/LunarUtil.dart +++ b/lib/calendar/util/LunarUtil.dart @@ -1005,7 +1005,7 @@ class LunarUtil { '6-6': ['天贶节'], '6-24': ['观莲节'], '6-25': ['五谷母节'], - '7-14': ['中元节'], + '7-15': ['中元节'], '7-22': ['财神节'], '7-29': ['地藏节'], '8-1': ['天灸日'], diff --git a/pubspec.yaml b/pubspec.yaml index 81c0537..d5a6763 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: lunar description: a calendar library for Solar and Chinese Lunar -version: 1.3.4 +version: 1.3.5 homepage: https://github.com/6tail/lunar-flutter environment: diff --git a/test/Solar_test.dart b/test/Solar_test.dart index 99bee6c..f28fe00 100644 --- a/test/Solar_test.dart +++ b/test/Solar_test.dart @@ -136,4 +136,24 @@ void main() { expect(solar.next(-5).toYmd(), '1582-09-30'); }); + test('24', () { + Solar solar = Solar.fromYmd(2023, 8, 31); + expect(solar.nextMonth(1).toYmd(), '2023-09-30'); + }); + + test('25', () { + Solar solar = Solar.fromYmd(2023, 8, 31); + expect(solar.nextMonth(2).toYmd(), '2023-10-31'); + }); + + test('26', () { + Solar solar = Solar.fromYmd(2023, 8, 31); + expect(solar.nextMonth(6).toYmd(), '2024-02-29'); + }); + + test('27', () { + Solar solar = Solar.fromYmd(2023, 8, 31); + expect(solar.nextYear(2).toYmd(), '2025-08-31'); + }); + }