From ceac1afc3e76c179bd494389a2e278dc5d8876b9 Mon Sep 17 00:00:00 2001 From: 6tail <6tail@6tail.cn> Date: Sun, 3 Sep 2023 11:39:25 +0800 Subject: [PATCH] =?UTF-8?q?v1.3.6=20=E4=B8=AD=E5=85=83=E8=8A=82=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=86=9C=E5=8E=86=E4=B8=83=E6=9C=88=E5=8D=81=E4=BA=94?= =?UTF-8?q?=EF=BC=9B=E4=BF=AE=E5=A4=8DSolar=E7=9A=84nextMonth=E8=B6=85?= =?UTF-8?q?=E6=9C=9F=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- README_EN.md | 2 +- pom.xml | 2 +- src/main/java/com/nlf/calendar/Solar.java | 25 ++++++++----------- .../java/com/nlf/calendar/util/LunarUtil.java | 2 +- src/test/java/test/SolarTest.java | 24 ++++++++++++++++++ 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b0ea924..2415e01 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历) cn.6tail lunar - 1.3.5 + 1.3.6 ``` diff --git a/README_EN.md b/README_EN.md index 6325f2a..33233b0 100644 --- a/README_EN.md +++ b/README_EN.md @@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar. cn.6tail lunar - 1.3.5 + 1.3.6 ``` diff --git a/pom.xml b/pom.xml index d146396..65724b0 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ cn.6tail lunar jar - 1.3.5 + 1.3.6 ${project.groupId}:${project.artifactId} https://github.com/6tail/lunar-java a calendar library for Solar and Chinese Lunar diff --git a/src/main/java/com/nlf/calendar/Solar.java b/src/main/java/com/nlf/calendar/Solar.java index 7e6874f..0851760 100644 --- a/src/main/java/com/nlf/calendar/Solar.java +++ b/src/main/java/com/nlf/calendar/Solar.java @@ -714,19 +714,17 @@ public Solar nextYear(int years) { 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 fromYmdHms(y, m, d, hour, minute, second); } @@ -740,18 +738,15 @@ public Solar nextMonth(int months) { 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 fromYmdHms(y, m, d, hour, minute, second); } diff --git a/src/main/java/com/nlf/calendar/util/LunarUtil.java b/src/main/java/com/nlf/calendar/util/LunarUtil.java index 9524070..1f612ae 100644 --- a/src/main/java/com/nlf/calendar/util/LunarUtil.java +++ b/src/main/java/com/nlf/calendar/util/LunarUtil.java @@ -159,7 +159,7 @@ public class LunarUtil{ put("6-6",Collections.nCopies(1,"天贶节")); put("6-24",Collections.nCopies(1,"观莲节")); put("6-25",Collections.nCopies(1,"五谷母节")); - put("7-14",Collections.nCopies(1,"中元节")); + put("7-15",Collections.nCopies(1,"中元节")); put("7-22",Collections.nCopies(1,"财神节")); put("7-29",Collections.nCopies(1,"地藏节")); put("8-1",Collections.nCopies(1,"天灸日")); diff --git a/src/test/java/test/SolarTest.java b/src/test/java/test/SolarTest.java index 3d125cc..bfa421c 100644 --- a/src/test/java/test/SolarTest.java +++ b/src/test/java/test/SolarTest.java @@ -171,4 +171,28 @@ public void test26(){ Assert.assertEquals("1582-09-29", solar.next(-6).toYmd()); } + @Test + public void test27(){ + Solar solar = Solar.fromYmd(2023, 8, 31); + Assert.assertEquals("2023-09-30", solar.nextMonth(1).toYmd()); + } + + @Test + public void test28(){ + Solar solar = Solar.fromYmd(2023, 8, 31); + Assert.assertEquals("2023-10-31", solar.nextMonth(2).toYmd()); + } + + @Test + public void test29(){ + Solar solar = Solar.fromYmd(2023, 8, 31); + Assert.assertEquals("2025-08-31", solar.nextYear(2).toYmd()); + } + + @Test + public void test30(){ + Solar solar = Solar.fromYmd(2023, 8, 31); + Assert.assertEquals("2024-02-29", solar.nextMonth(6).toYmd()); + } + }