From 12a8eec1230588ab1b6e5ba7fad7216257b6bc69 Mon Sep 17 00:00:00 2001
From: 6tail <6tail@6tail.cn>
Date: Fri, 25 Nov 2022 20:58:49 +0800
Subject: [PATCH] =?UTF-8?q?v1.2.27=20=E4=BF=AE=E5=A4=8D=E7=AB=8B=E6=98=A5?=
=?UTF-8?q?=E6=AF=94=E6=98=A5=E8=8A=82=E6=97=A9=E6=97=B6=E5=B9=B4=E4=B9=9D?=
=?UTF-8?q?=E6=98=9F=E7=9A=84=E9=94=99=E8=AF=AF=EF=BC=9B=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?=E9=98=B3=E5=8E=86=E6=9C=88=E4=B8=AD=E8=8E=B7=E5=8F=96=E5=91=A8?=
=?UTF-8?q?=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 3 ++-
README.md | 4 +--
README_EN.md | 4 +--
pom.xml | 2 +-
src/main/java/com/nlf/calendar/Lunar.java | 13 ++++++----
.../java/com/nlf/calendar/SolarMonth.java | 20 ++++++++++++++
src/test/java/test/BaZiTest.java | 18 +++++++++++++
src/test/java/test/LunarTest.java | 12 ---------
src/test/java/test/NineStarTest.java | 26 +++++++++++++++++++
9 files changed, 79 insertions(+), 23 deletions(-)
create mode 100644 src/test/java/test/NineStarTest.java
diff --git a/.gitignore b/.gitignore
index e8ff194..05327a2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,4 +13,5 @@ target/
*.cache
*.diff
*.patch
-*.tmp
\ No newline at end of file
+*.tmp
+.DS_Store
\ No newline at end of file
diff --git a/README.md b/README.md
index c281b9c..04841a5 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
cn.6tail
lunar
- 1.2.25
+ 1.2.27
```
@@ -53,4 +53,4 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
## 文档
-请移步至 [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")
+请移步至 [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")
diff --git a/README_EN.md b/README_EN.md
index bd4ecbb..855c044 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.2.25
+ 1.2.27
```
@@ -49,4 +49,4 @@ Output:
## Documentation
-Please visit [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")
+Please visit [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")
diff --git a/pom.xml b/pom.xml
index 856f049..7e1d187 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
cn.6tail
lunar
jar
- 1.2.26
+ 1.2.27
${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/Lunar.java b/src/main/java/com/nlf/calendar/Lunar.java
index c8b142a..c81fc4b 100644
--- a/src/main/java/com/nlf/calendar/Lunar.java
+++ b/src/main/java/com/nlf/calendar/Lunar.java
@@ -2049,13 +2049,16 @@ public class Lunar {
}
protected NineStar getYearNineStar(String yearInGanZhi) {
- int index = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
- int yearOffset = 0;
- if (index != LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1) {
- yearOffset = -1;
+ int indexExact = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
+ int index = LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1;
+ int yearOffset = indexExact - index;
+ if (yearOffset > 1) {
+ yearOffset -= 60;
+ } else if (yearOffset < -1) {
+ yearOffset += 60;
}
int yuan = ((this.year + yearOffset + 2696) / 60) % 3;
- int offset = (62 + yuan * 3 - index) % 9;
+ int offset = (62 + yuan * 3 - indexExact) % 9;
if (0 == offset) {
offset = 9;
}
diff --git a/src/main/java/com/nlf/calendar/SolarMonth.java b/src/main/java/com/nlf/calendar/SolarMonth.java
index b95af55..14eed6f 100644
--- a/src/main/java/com/nlf/calendar/SolarMonth.java
+++ b/src/main/java/com/nlf/calendar/SolarMonth.java
@@ -122,6 +122,26 @@ public class SolarMonth {
return l;
}
+ /**
+ * 获取本月的阳历周列表
+ * @param start 星期几作为一周的开始,1234560分别代表星期一至星期天
+ * @return 周列表
+ */
+ public List getWeeks(int start) {
+ List l = new ArrayList();
+ SolarWeek week = SolarWeek.fromYmd(year, month, 1, start);
+ Solar firstDay = week.getFirstDay();
+ while (true) {
+ l.add(week);
+ week = week.next(1, false);
+ firstDay = week.getFirstDay();
+ if (firstDay.getYear() > year || firstDay.getMonth() > month) {
+ break;
+ }
+ }
+ return l;
+ }
+
/**
* 获取往后推几个月的阳历月,如果要往前推,则月数用负数
*
diff --git a/src/test/java/test/BaZiTest.java b/src/test/java/test/BaZiTest.java
index e9aeed9..abd80a0 100644
--- a/src/test/java/test/BaZiTest.java
+++ b/src/test/java/test/BaZiTest.java
@@ -258,6 +258,14 @@ public class BaZiTest {
}
}
+ @Test
+ public void testBaZi2Solar1() {
+ List l = Solar.fromBaZi("壬寅","庚戌","己未","乙亥");
+ for(Solar s:l){
+ System.out.println(s.toFullString());
+ }
+ }
+
@Test
public void test4() {
Lunar lunar = Lunar.fromYmd(1985, 12, 27);
@@ -295,4 +303,14 @@ public class BaZiTest {
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
}
+
+ @Test
+ public void test13(){
+ Lunar lunar = Lunar.fromYmdHms(1991, 4, 5, 3, 37, 0);
+ EightChar eightChar = lunar.getEightChar();
+ Assert.assertEquals("年柱", "辛未", eightChar.getYear());
+ Assert.assertEquals("月柱", "癸巳", eightChar.getMonth());
+ Assert.assertEquals("日柱", "戊子", eightChar.getDay());
+ Assert.assertEquals("时柱", "甲寅", eightChar.getTime());
+ }
}
diff --git a/src/test/java/test/LunarTest.java b/src/test/java/test/LunarTest.java
index f843584..641dfcd 100644
--- a/src/test/java/test/LunarTest.java
+++ b/src/test/java/test/LunarTest.java
@@ -161,18 +161,6 @@ public class LunarTest {
Assert.assertEquals("2033-12-22", lunar.getSolar().toYmd());
}
- @Test
- public void test23() {
- Lunar lunar = Lunar.fromYmd(2022, 1, 1);
- Assert.assertEquals("六白金开阳", lunar.getYearNineStar().toString());
- }
-
- @Test
- public void test24() {
- Lunar lunar = Lunar.fromYmd(2033, 1, 1);
- Assert.assertEquals("四绿木天权", lunar.getYearNineStar().toString());
- }
-
@Test
public void test25() {
Solar solar = new Solar(2021, 6, 7, 21, 18, 0);
diff --git a/src/test/java/test/NineStarTest.java b/src/test/java/test/NineStarTest.java
new file mode 100644
index 0000000..b9b657f
--- /dev/null
+++ b/src/test/java/test/NineStarTest.java
@@ -0,0 +1,26 @@
+package test;
+
+import com.nlf.calendar.Lunar;
+import com.nlf.calendar.Solar;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NineStarTest {
+ @Test
+ public void test1() {
+ Lunar lunar = Solar.fromYmd(1985, 2, 19).getLunar();
+ Assert.assertEquals("六", lunar.getYearNineStar().getNumber());
+ }
+
+ @Test
+ public void test2() {
+ Lunar lunar = Lunar.fromYmd(2022, 1, 1);
+ Assert.assertEquals("六白金开阳", lunar.getYearNineStar().toString());
+ }
+
+ @Test
+ public void test3() {
+ Lunar lunar = Lunar.fromYmd(2033, 1, 1);
+ Assert.assertEquals("四绿木天权", lunar.getYearNineStar().toString());
+ }
+}