Skip to content

Commit

Permalink
v1.3.5 中元节改为农历七月十五;修复Solar的nextMonth超期问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
6tail committed Sep 5, 2023
1 parent d6b9687 commit 9136d39
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,7 @@
1. Solar增加薪资比例;
2. 修正与寿星v5.10的节气误差;
3. 修复古时阴阳历转换错误的问题。

## 1.3.5
1. 中元节改为农历七月十五;
2. 修复Solar的nextMonth超期问题。
25 changes: 10 additions & 15 deletions lib/calendar/Solar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/calendar/util/LunarUtil.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ class LunarUtil {
'6-6': ['天贶节'],
'6-24': ['观莲节'],
'6-25': ['五谷母节'],
'7-14': ['中元节'],
'7-15': ['中元节'],
'7-22': ['财神节'],
'7-29': ['地藏节'],
'8-1': ['天灸日'],
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
20 changes: 20 additions & 0 deletions test/Solar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

}

0 comments on commit 9136d39

Please sign in to comment.