Skip to content

Commit 12a8eec

Browse files
committed
v1.2.27 修复立春比春节早时年九星的错误;新增阳历月中获取周。
1 parent 51afe36 commit 12a8eec

9 files changed

Lines changed: 79 additions & 23 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ target/
1313
*.cache
1414
*.diff
1515
*.patch
16-
*.tmp
16+
*.tmp
17+
.DS_Store

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
1616
<dependency>
1717
<groupId>cn.6tail</groupId>
1818
<artifactId>lunar</artifactId>
19-
<version>1.2.25</version>
19+
<version>1.2.27</version>
2020
</dependency>
2121
```
2222

@@ -53,4 +53,4 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
5353

5454
## 文档
5555

56-
请移步至 [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")
56+
请移步至 [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")

README_EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
1212
<dependency>
1313
<groupId>cn.6tail</groupId>
1414
<artifactId>lunar</artifactId>
15-
<version>1.2.25</version>
15+
<version>1.2.27</version>
1616
</dependency>
1717
```
1818

@@ -49,4 +49,4 @@ Output:
4949

5050
## Documentation
5151

52-
Please visit [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")
52+
Please visit [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>cn.6tail</groupId>
88
<artifactId>lunar</artifactId>
99
<packaging>jar</packaging>
10-
<version>1.2.26</version>
10+
<version>1.2.27</version>
1111
<name>${project.groupId}:${project.artifactId}</name>
1212
<url>https://github.com/6tail/lunar-java</url>
1313
<description>a calendar library for Solar and Chinese Lunar</description>

src/main/java/com/nlf/calendar/Lunar.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,13 +2049,16 @@ public String getYueXiang() {
20492049
}
20502050

20512051
protected NineStar getYearNineStar(String yearInGanZhi) {
2052-
int index = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
2053-
int yearOffset = 0;
2054-
if (index != LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1) {
2055-
yearOffset = -1;
2052+
int indexExact = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
2053+
int index = LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1;
2054+
int yearOffset = indexExact - index;
2055+
if (yearOffset > 1) {
2056+
yearOffset -= 60;
2057+
} else if (yearOffset < -1) {
2058+
yearOffset += 60;
20562059
}
20572060
int yuan = ((this.year + yearOffset + 2696) / 60) % 3;
2058-
int offset = (62 + yuan * 3 - index) % 9;
2061+
int offset = (62 + yuan * 3 - indexExact) % 9;
20592062
if (0 == offset) {
20602063
offset = 9;
20612064
}

src/main/java/com/nlf/calendar/SolarMonth.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ public List<Solar> getDays() {
122122
return l;
123123
}
124124

125+
/**
126+
* 获取本月的阳历周列表
127+
* @param start 星期几作为一周的开始,1234560分别代表星期一至星期天
128+
* @return 周列表
129+
*/
130+
public List<SolarWeek> getWeeks(int start) {
131+
List<SolarWeek> l = new ArrayList<SolarWeek>();
132+
SolarWeek week = SolarWeek.fromYmd(year, month, 1, start);
133+
Solar firstDay = week.getFirstDay();
134+
while (true) {
135+
l.add(week);
136+
week = week.next(1, false);
137+
firstDay = week.getFirstDay();
138+
if (firstDay.getYear() > year || firstDay.getMonth() > month) {
139+
break;
140+
}
141+
}
142+
return l;
143+
}
144+
125145
/**
126146
* 获取往后推几个月的阳历月,如果要往前推,则月数用负数
127147
*

src/test/java/test/BaZiTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ public void testBaZi2Solar() {
258258
}
259259
}
260260

261+
@Test
262+
public void testBaZi2Solar1() {
263+
List<Solar> l = Solar.fromBaZi("壬寅","庚戌","己未","乙亥");
264+
for(Solar s:l){
265+
System.out.println(s.toFullString());
266+
}
267+
}
268+
261269
@Test
262270
public void test4() {
263271
Lunar lunar = Lunar.fromYmd(1985, 12, 27);
@@ -295,4 +303,14 @@ public void test11(){
295303
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
296304
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
297305
}
306+
307+
@Test
308+
public void test13(){
309+
Lunar lunar = Lunar.fromYmdHms(1991, 4, 5, 3, 37, 0);
310+
EightChar eightChar = lunar.getEightChar();
311+
Assert.assertEquals("年柱", "辛未", eightChar.getYear());
312+
Assert.assertEquals("月柱", "癸巳", eightChar.getMonth());
313+
Assert.assertEquals("日柱", "戊子", eightChar.getDay());
314+
Assert.assertEquals("时柱", "甲寅", eightChar.getTime());
315+
}
298316
}

src/test/java/test/LunarTest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,6 @@ public void test22() {
161161
Assert.assertEquals("2033-12-22", lunar.getSolar().toYmd());
162162
}
163163

164-
@Test
165-
public void test23() {
166-
Lunar lunar = Lunar.fromYmd(2022, 1, 1);
167-
Assert.assertEquals("六白金开阳", lunar.getYearNineStar().toString());
168-
}
169-
170-
@Test
171-
public void test24() {
172-
Lunar lunar = Lunar.fromYmd(2033, 1, 1);
173-
Assert.assertEquals("四绿木天权", lunar.getYearNineStar().toString());
174-
}
175-
176164
@Test
177165
public void test25() {
178166
Solar solar = new Solar(2021, 6, 7, 21, 18, 0);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package test;
2+
3+
import com.nlf.calendar.Lunar;
4+
import com.nlf.calendar.Solar;
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
8+
public class NineStarTest {
9+
@Test
10+
public void test1() {
11+
Lunar lunar = Solar.fromYmd(1985, 2, 19).getLunar();
12+
Assert.assertEquals("六", lunar.getYearNineStar().getNumber());
13+
}
14+
15+
@Test
16+
public void test2() {
17+
Lunar lunar = Lunar.fromYmd(2022, 1, 1);
18+
Assert.assertEquals("六白金开阳", lunar.getYearNineStar().toString());
19+
}
20+
21+
@Test
22+
public void test3() {
23+
Lunar lunar = Lunar.fromYmd(2033, 1, 1);
24+
Assert.assertEquals("四绿木天权", lunar.getYearNineStar().toString());
25+
}
26+
}

0 commit comments

Comments
 (0)