Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbab78d641 | ||
|
|
a44ced263d | ||
|
|
bd19489441 | ||
|
|
a235e076db | ||
|
|
4995e3f9d0 | ||
|
|
554c474e4d | ||
|
|
316e9b7b88 | ||
|
|
b220249cd7 | ||
|
|
147499032b | ||
|
|
954c841944 | ||
|
|
1cff6441f7 | ||
|
|
622294e74b | ||
|
|
12a4bb0efa | ||
|
|
6abe5ae1a2 | ||
|
|
135d39b751 | ||
|
|
85d56e5c3b | ||
|
|
b7fac53a81 | ||
|
|
72c4d0df71 | ||
|
|
10beaefd34 | ||
|
|
f1be26456d | ||
|
|
cc9444aa03 | ||
|
|
df6119c19e | ||
|
|
c7cd454f2d | ||
|
|
5680eb8d44 | ||
|
|
392ac5b00a | ||
|
|
9ec735cd4b | ||
|
|
e06c7a0532 | ||
|
|
bd18254834 | ||
|
|
28dbf8f45f | ||
|
|
0d1f64664e | ||
|
|
cc2bbb5049 | ||
|
|
9bb808da35 | ||
|
|
e29ab49618 |
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.1.4</version>
|
||||
<version>1.1.15</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -44,7 +44,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
|
||||
|
||||
### 下载jar
|
||||
|
||||
如果使用jar,建议下载最新的SNAPSHOT版本,bug将得到及时的修复。
|
||||
如果使用jar,建议下载最新的版本,bug将得到及时的修复。
|
||||
|
||||
[Download](https://github.com/6tail/lunar-java/releases)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.1.4</version>
|
||||
<version>1.1.15</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -40,7 +40,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
|
||||
|
||||
### Download
|
||||
|
||||
If you will use jars in your projects, I suggest you to download latest snapshot versions with less bugs.
|
||||
If you will use jars in your projects, I suggest you to download latest versions with less bugs.
|
||||
|
||||
[Download](https://github.com/6tail/lunar-java/releases)
|
||||
|
||||
|
||||
4
pom.xml
4
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.4</version>
|
||||
<version>1.1.15</version>
|
||||
<name>${project.groupId}:${project.artifactId}</name>
|
||||
<url>https://github.com/6tail/lunar-java</url>
|
||||
<description>a calendar library for Solar and Chinese Lunar</description>
|
||||
@@ -60,7 +60,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -30,11 +30,11 @@ public class EightChar {
|
||||
|
||||
{
|
||||
//阳
|
||||
put("甲", 11);
|
||||
put("丙", 2);
|
||||
put("戊", 2);
|
||||
put("庚", 5);
|
||||
put("壬", 8);
|
||||
put("甲", 1);
|
||||
put("丙", 10);
|
||||
put("戊", 10);
|
||||
put("庚", 7);
|
||||
put("壬", 4);
|
||||
//阴
|
||||
put("乙", 6);
|
||||
put("丁", 9);
|
||||
@@ -524,5 +524,67 @@ public class EightChar {
|
||||
return new Yun(this, gender);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年柱所在旬
|
||||
* @return 旬
|
||||
*/
|
||||
public String getYearXun(){
|
||||
return lunar.getYearXunExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年柱旬空(空亡)
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getYearXunKong(){
|
||||
return lunar.getYearXunKongExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月柱所在旬
|
||||
* @return 旬
|
||||
*/
|
||||
public String getMonthXun(){
|
||||
return lunar.getMonthXunExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月柱旬空(空亡)
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getMonthXunKong(){
|
||||
return lunar.getMonthXunKongExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日柱所在旬
|
||||
* @return 旬
|
||||
*/
|
||||
public String getDayXun(){
|
||||
return lunar.getDayXunExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日柱旬空(空亡)
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getDayXunKong(){
|
||||
return lunar.getDayXunKongExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时柱所在旬
|
||||
* @return 旬
|
||||
*/
|
||||
public String getTimeXun(){
|
||||
return lunar.getTimeXun();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时柱旬空(空亡)
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getTimeXunKong(){
|
||||
return lunar.getTimeXunKong();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,14 @@ public class Lunar{
|
||||
public static final String JIE_QI_FIRST = "冬至";
|
||||
/** 农历年末节气名(节令:大雪) */
|
||||
public static final String JIE_QI_LAST = "大雪";
|
||||
/** 节气表尾部追加阳历下年初的第一个节气名(节令:小寒),以示区分 */
|
||||
public static final String JIE_APPEND_SOLAR_FIRST = "XIAO_HAN";
|
||||
/** 节气表尾部追加阳历下年初的第二个节气名(气令:大寒),以示区分 */
|
||||
public static final String QI_APPEND_SOLAR_SECOND = "DA_HAN";
|
||||
/** 阳历下年初的第一个节气名(节令:小寒) */
|
||||
public static final String JIE_SOLAR_FIRST = "小寒";
|
||||
/** 阳历下年初的第二个节气名(气令:大寒) */
|
||||
public static final String QI_SOLAR_SECOND = "大寒";
|
||||
/** 1弧度对应的角秒 */
|
||||
private static final double SECOND_PER_RAD = 180 * 3600 / Math.PI;
|
||||
/** 节气表,国标以冬至为首个节气 */
|
||||
@@ -315,7 +323,7 @@ public class Lunar{
|
||||
t -= (53 * t * t + 334116 * Math.cos(4.67 + 628.307585 * t) + 2061 * Math.cos(2.678 + 628.3076 * t) * t) / v / 10000000;
|
||||
l = 48950621.66 + 6283319653.318 * t + 53 * t * t + 334166 * Math.cos(4.669257 + 628.307585 * t) + 3489 * Math.cos(4.6261 + 1256.61517 * t) + 2060.6 * Math.cos(2.67823 + 628.307585 * t) * t - 994 - 834 * Math.sin(2.1824 - 33.75705 * t);
|
||||
t -= (l / 10000000 - w) / 628.332 + (32 * (t + 1.8) * (t + 1.8) - 20) / 86400 / 36525;
|
||||
return t * 36525 + 8 / 24;
|
||||
return t * 36525 + 8D / 24;
|
||||
}
|
||||
|
||||
private double saLonT2(double w){
|
||||
@@ -328,10 +336,10 @@ public class Lunar{
|
||||
|
||||
private double qiHigh(double w){
|
||||
double t = saLonT2(w) * 36525;
|
||||
t = t - dtT(t) + 8 / 24;
|
||||
t = t - dtT(t) + 8D / 24;
|
||||
double v = ((t + 0.5) % 1) * 86400;
|
||||
if (v < 1200 || v > 86400 - 1200){
|
||||
t = saLonT(w) * 36525 - dtT(t) + 8 / 24;
|
||||
t = saLonT(w) * 36525 - dtT(t) + 8D / 24;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
@@ -373,7 +381,7 @@ public class Lunar{
|
||||
|
||||
private double qiAccurate(double w){
|
||||
double t = saLonT(w) * 36525;
|
||||
return t - dtT(t) + 8 * 1D / 24;
|
||||
return t - dtT(t) + 8D / 24;
|
||||
}
|
||||
|
||||
private double qiAccurate2(double jd) {
|
||||
@@ -408,12 +416,23 @@ public class Lunar{
|
||||
//追加下一农历年初的冬至
|
||||
q = calcJieQi(w + 15.2184 * size);
|
||||
jieQi.put(JIE_QI_APPEND, Solar.fromJulianDay(qiAccurate2(q) + Solar.J2000));
|
||||
|
||||
//追加下一阳历年初的小寒
|
||||
size++;
|
||||
q = calcJieQi(w + 15.2184 * size);
|
||||
jieQi.put(JIE_APPEND_SOLAR_FIRST, Solar.fromJulianDay(qiAccurate2(q) + Solar.J2000));
|
||||
|
||||
//追加下一阳历年初的大寒
|
||||
size++;
|
||||
q = calcJieQi(w + 15.2184 * size);
|
||||
jieQi.put(QI_APPEND_SOLAR_SECOND, Solar.fromJulianDay(qiAccurate2(q) + Solar.J2000));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算干支纪年
|
||||
*/
|
||||
private void computeYear(){
|
||||
//以正月初一开始
|
||||
yearGanIndex = (year+LunarUtil.BASE_YEAR_GANZHI_INDEX)%10;
|
||||
yearZhiIndex = (year+LunarUtil.BASE_YEAR_GANZHI_INDEX)%12;
|
||||
|
||||
@@ -425,32 +444,57 @@ public class Lunar{
|
||||
int gExact = yearGanIndex;
|
||||
int zExact = yearZhiIndex;
|
||||
|
||||
//获取立春的阳历时刻
|
||||
Solar liChun = jieQi.get("立春");
|
||||
|
||||
//阳历和阴历年份相同代表正月初一及以后
|
||||
if(year==solar.getYear()){
|
||||
//获取立春的阳历时刻
|
||||
Solar liChun = jieQi.get("立春");
|
||||
//立春日期判断
|
||||
if(solar.toYmd().compareTo(liChun.toYmd())<0) {
|
||||
g--;
|
||||
if(g<0){
|
||||
g += 10;
|
||||
}
|
||||
z--;
|
||||
if(z<0){
|
||||
z += 12;
|
||||
}
|
||||
}
|
||||
//立春交接时刻判断
|
||||
if(solar.toYmdHms().compareTo(liChun.toYmdHms())<0) {
|
||||
gExact--;
|
||||
if(gExact<0){
|
||||
gExact += 10;
|
||||
}
|
||||
zExact--;
|
||||
if(zExact<0){
|
||||
zExact += 12;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(solar.toYmd().compareTo(liChun.toYmd())>=0) {
|
||||
g++;
|
||||
z++;
|
||||
}
|
||||
if(solar.toYmdHms().compareTo(liChun.toYmdHms())>=0) {
|
||||
gExact++;
|
||||
zExact++;
|
||||
}
|
||||
}
|
||||
|
||||
if(g<0){
|
||||
g += 10;
|
||||
}
|
||||
if(g>=10){
|
||||
g-=10;
|
||||
}
|
||||
if(z<0){
|
||||
z += 12;
|
||||
}
|
||||
if(z>=12){
|
||||
z-=12;
|
||||
}
|
||||
if(gExact<0){
|
||||
gExact += 10;
|
||||
}
|
||||
if(gExact>=10){
|
||||
gExact-=10;
|
||||
}
|
||||
if(zExact<0){
|
||||
zExact += 12;
|
||||
}
|
||||
if(zExact>=12){
|
||||
zExact-=12;
|
||||
}
|
||||
|
||||
yearGanIndexByLiChun = g;
|
||||
yearZhiIndexByLiChun = z;
|
||||
|
||||
@@ -953,6 +997,11 @@ public class Lunar{
|
||||
if(d.getYear()==solar.getYear()&&d.getMonth()==solar.getMonth()&&d.getDay()==solar.getDay()){
|
||||
return JIE_QI_LAST;
|
||||
}
|
||||
// 追加的节令:小寒
|
||||
d = jieQi.get(JIE_APPEND_SOLAR_FIRST);
|
||||
if(d.getYear()==solar.getYear()&&d.getMonth()==solar.getMonth()&&d.getDay()==solar.getDay()){
|
||||
return JIE_SOLAR_FIRST;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -973,6 +1022,11 @@ public class Lunar{
|
||||
if(d.getYear()==solar.getYear()&&d.getMonth()==solar.getMonth()&&d.getDay()==solar.getDay()){
|
||||
return JIE_QI_FIRST;
|
||||
}
|
||||
// 追加的气令:大寒
|
||||
d = jieQi.get(QI_APPEND_SOLAR_SECOND);
|
||||
if(d.getYear()==solar.getYear()&&d.getMonth()==solar.getMonth()&&d.getDay()==solar.getDay()){
|
||||
return QI_SOLAR_SECOND;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -1849,8 +1903,11 @@ public class Lunar{
|
||||
}
|
||||
// 寅月起,所以需要-2
|
||||
int monthIndex = monthZhiIndex-2;
|
||||
if(monthIndex<0){
|
||||
monthIndex += 12;
|
||||
}
|
||||
int index = start-monthIndex-1;
|
||||
if(index<0){
|
||||
while(index<0){
|
||||
index += 9;
|
||||
}
|
||||
return new NineStar(index);
|
||||
@@ -2004,6 +2061,12 @@ public class Lunar{
|
||||
if(JIE_QI_PREPEND.equals(jq)){
|
||||
jq = JIE_QI_LAST;
|
||||
}
|
||||
if(JIE_APPEND_SOLAR_FIRST.equals(jq)){
|
||||
jq = JIE_SOLAR_FIRST;
|
||||
}
|
||||
if(QI_APPEND_SOLAR_SECOND.equals(jq)){
|
||||
jq = QI_SOLAR_SECOND;
|
||||
}
|
||||
if(filter){
|
||||
if(!filters.contains(jq)){
|
||||
continue;
|
||||
@@ -2052,6 +2115,10 @@ public class Lunar{
|
||||
name = JIE_QI_FIRST;
|
||||
}else if(JIE_QI_PREPEND.equals(name)){
|
||||
name = JIE_QI_LAST;
|
||||
}else if(JIE_APPEND_SOLAR_FIRST.equals(name)){
|
||||
name = JIE_SOLAR_FIRST;
|
||||
}else if(QI_APPEND_SOLAR_SECOND.equals(name)){
|
||||
name = QI_SOLAR_SECOND;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
@@ -2271,4 +2338,183 @@ public class Lunar{
|
||||
}
|
||||
return eightChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取往后推几天的农历日期,如果要往前推,则天数用负数
|
||||
* @param days 天数
|
||||
* @return 农历日期
|
||||
*/
|
||||
public Lunar next(int days){
|
||||
int y = year;
|
||||
int m = month;
|
||||
int d = day;
|
||||
if(days>0){
|
||||
int daysInMonth = LunarUtil.getDaysOfMonth(y,m);
|
||||
int rest = day+days;
|
||||
while(daysInMonth < rest) {
|
||||
if(m>0){
|
||||
if(LunarUtil.getLeapMonth(y)!=m){
|
||||
m++;
|
||||
}else{
|
||||
m = -m;
|
||||
}
|
||||
}else{
|
||||
m = 1-m;
|
||||
}
|
||||
if(13==m){
|
||||
y++;
|
||||
m=1;
|
||||
}
|
||||
rest -= daysInMonth;
|
||||
daysInMonth = LunarUtil.getDaysOfMonth(y,m);
|
||||
}
|
||||
d = rest;
|
||||
}else if(days<0){
|
||||
int daysInMonth = day;
|
||||
int rest = -days;
|
||||
while(daysInMonth <= rest) {
|
||||
if(m>0){
|
||||
m--;
|
||||
if(0==m){
|
||||
y--;
|
||||
m = LunarUtil.getLeapMonth(y)!=12?12:-12;
|
||||
}
|
||||
}else{
|
||||
m = -m;
|
||||
}
|
||||
rest -= daysInMonth;
|
||||
daysInMonth = LunarUtil.getDaysOfMonth(y,m);
|
||||
}
|
||||
d = daysInMonth - rest;
|
||||
}
|
||||
return new Lunar(y,m,d,hour,minute,second);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年所在旬(以正月初一作为新年的开始)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getYearXun(){
|
||||
return LunarUtil.getXun(getYearInGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年所在旬(以立春当天作为新年的开始)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getYearXunByLiChun(){
|
||||
return LunarUtil.getXun(getYearInGanZhiByLiChun());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年所在旬(以立春交接时刻作为新年的开始)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getYearXunExact(){
|
||||
return LunarUtil.getXun(getYearInGanZhiExact());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值年空亡(以正月初一作为新年的开始)
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getYearXunKong(){
|
||||
return LunarUtil.getXunKong(getYearInGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值年空亡(以立春当天作为新年的开始)
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getYearXunKongByLiChun(){
|
||||
return LunarUtil.getXunKong(getYearInGanZhiByLiChun());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值年空亡(以立春交接时刻作为新年的开始)
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getYearXunKongExact(){
|
||||
return LunarUtil.getXunKong(getYearInGanZhiExact());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月所在旬(以节交接当天起算)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getMonthXun(){
|
||||
return LunarUtil.getXun(getMonthInGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月所在旬(以节交接时刻起算)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getMonthXunExact(){
|
||||
return LunarUtil.getXun(getMonthInGanZhiExact());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值月空亡(以节交接当天起算)
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getMonthXunKong(){
|
||||
return LunarUtil.getXunKong(getMonthInGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值月空亡(以节交接时刻起算)
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getMonthXunKongExact(){
|
||||
return LunarUtil.getXunKong(getMonthInGanZhiExact());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日所在旬(以节交接当天起算)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getDayXun(){
|
||||
return LunarUtil.getXun(getDayInGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日所在旬(晚子时算第二天)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getDayXunExact(){
|
||||
return LunarUtil.getXun(getDayInGanZhiExact());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值日空亡
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getDayXunKong(){
|
||||
return LunarUtil.getXunKong(getDayInGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值日空亡(晚子时算第二天)
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getDayXunKongExact(){
|
||||
return LunarUtil.getXunKong(getDayInGanZhiExact());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时辰所在旬
|
||||
* @return 旬
|
||||
*/
|
||||
public String getTimeXun(){
|
||||
return LunarUtil.getXun(getTimeInGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值时空亡
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getTimeXunKong(){
|
||||
return LunarUtil.getXunKong(getTimeInGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.nlf.calendar.util.HolidayUtil;
|
||||
import com.nlf.calendar.util.LunarUtil;
|
||||
import com.nlf.calendar.util.SolarUtil;
|
||||
|
||||
@@ -323,15 +324,10 @@ public class Solar{
|
||||
l.add(f);
|
||||
}
|
||||
//计算几月第几个星期几对应的节日
|
||||
//第几周
|
||||
int weekInMonth = calendar.get(Calendar.WEEK_OF_MONTH);
|
||||
int weeks = (int)Math.ceil(day/7D);
|
||||
//星期几,0代表星期天
|
||||
int week = getWeek();
|
||||
//星期天很奇葩,会多算一周,需要减掉
|
||||
if(0==week){
|
||||
weekInMonth--;
|
||||
}
|
||||
f = SolarUtil.WEEK_FESTIVAL.get(month+"-"+weekInMonth+"-"+week);
|
||||
f = SolarUtil.WEEK_FESTIVAL.get(month+"-"+weeks+"-"+week);
|
||||
if(null!=f){
|
||||
l.add(f);
|
||||
}
|
||||
@@ -536,9 +532,36 @@ public class Solar{
|
||||
* @return 阳历日期
|
||||
*/
|
||||
public Solar next(int days){
|
||||
return next(days,false);
|
||||
}
|
||||
|
||||
public Solar next(int days, boolean onlyWorkday){
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(year,month-1,day,hour,minute,second);
|
||||
c.add(Calendar.DATE,days);
|
||||
if(0!=days) {
|
||||
if(!onlyWorkday){
|
||||
c.add(Calendar.DATE,days);
|
||||
}else {
|
||||
int rest = Math.abs(days);
|
||||
int add = days < 1 ? -1 : 1;
|
||||
while (rest > 0) {
|
||||
c.add(Calendar.DATE, add);
|
||||
boolean work = true;
|
||||
Holiday holiday = HolidayUtil.getHoliday(c.get(Calendar.YEAR), c.get(Calendar.MONTH)+1, c.get(Calendar.DAY_OF_MONTH));
|
||||
if(null==holiday){
|
||||
int week = c.get(Calendar.DAY_OF_WEEK);
|
||||
if(1==week||7==week){
|
||||
work = false;
|
||||
}
|
||||
}else{
|
||||
work = holiday.isWork();
|
||||
}
|
||||
if(work){
|
||||
rest--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Solar(c);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,16 +39,17 @@ public class DaYun {
|
||||
this.yun = yun;
|
||||
this.lunar = yun.getLunar();
|
||||
this.index = index;
|
||||
int birthYear = lunar.getSolar().getYear();
|
||||
int year = yun.getStartSolar().getYear();
|
||||
if (index < 1) {
|
||||
this.startYear = lunar.getSolar().getYear();
|
||||
this.startYear = birthYear;
|
||||
this.startAge = 1;
|
||||
this.endYear = year - 1;
|
||||
this.endAge = yun.getStartYear();
|
||||
this.endAge = year - birthYear;
|
||||
} else {
|
||||
int add = (index - 1) * 10;
|
||||
this.startYear = year + add;
|
||||
this.startAge = yun.getStartYear() + add + 1;
|
||||
this.startAge = this.startYear - birthYear + 1;
|
||||
this.endYear = this.startYear + 9;
|
||||
this.endAge = this.startAge + 9;
|
||||
}
|
||||
@@ -99,6 +100,22 @@ public class DaYun {
|
||||
return LunarUtil.JIA_ZI[offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所在旬
|
||||
* @return 旬
|
||||
*/
|
||||
public String getXun(){
|
||||
return LunarUtil.getXun(getGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取旬空(空亡)
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getXunKong(){
|
||||
return LunarUtil.getXunKong(getGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流年
|
||||
*
|
||||
|
||||
@@ -53,7 +53,8 @@ public class LiuNian {
|
||||
* @return 干支
|
||||
*/
|
||||
public String getGanZhi() {
|
||||
int offset = LunarUtil.getJiaZiIndex(lunar.getYearInGanZhiExact()) + this.index;
|
||||
// 干支与出生日期和起运日期都没关系
|
||||
int offset = LunarUtil.getJiaZiIndex(lunar.getJieQiTable().get("立春").getLunar().getYearInGanZhiExact()) + this.index;
|
||||
if (daYun.getIndex() > 0) {
|
||||
offset += daYun.getStartAge() - 1;
|
||||
}
|
||||
@@ -61,6 +62,26 @@ public class LiuNian {
|
||||
return LunarUtil.JIA_ZI[offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所在旬
|
||||
* @return 旬
|
||||
*/
|
||||
public String getXun(){
|
||||
return LunarUtil.getXun(getGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取旬空(空亡)
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getXunKong(){
|
||||
return LunarUtil.getXunKong(getGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流月
|
||||
* @return 流月
|
||||
*/
|
||||
public LiuYue[] getLiuYue() {
|
||||
int n = 12;
|
||||
LiuYue[] l = new LiuYue[n];
|
||||
|
||||
@@ -61,4 +61,20 @@ public class LiuYue {
|
||||
String zhi = LunarUtil.ZHI[(index + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12 + 1];
|
||||
return gan + zhi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所在旬
|
||||
* @return 旬
|
||||
*/
|
||||
public String getXun(){
|
||||
return LunarUtil.getXun(getGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取旬空(空亡)
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getXunKong(){
|
||||
return LunarUtil.getXunKong(getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,4 +71,20 @@ public class XiaoYun {
|
||||
offset %= size;
|
||||
return LunarUtil.JIA_ZI[offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所在旬
|
||||
* @return 旬
|
||||
*/
|
||||
public String getXun(){
|
||||
return LunarUtil.getXun(getGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取旬空(空亡)
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getXunKong(){
|
||||
return LunarUtil.getXunKong(getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -31,6 +31,10 @@ public class LunarUtil{
|
||||
public static final int[] LEAP_MONTH_YEAR = {6,14,19,25,33,36,38,41,44,52,55,79,117,136,147,150,155,158,185,193};
|
||||
/** 闰月表 */
|
||||
public static final int[] LUNAR_MONTH = {0x00,0x04,0xad,0x08,0x5a,0x01,0xd5,0x54,0xb4,0x09,0x64,0x05,0x59,0x45,0x95,0x0a,0xa6,0x04,0x55,0x24,0xad,0x08,0x5a,0x62,0xda,0x04,0xb4,0x05,0xb4,0x55,0x52,0x0d,0x94,0x0a,0x4a,0x2a,0x56,0x02,0x6d,0x71,0x6d,0x01,0xda,0x02,0xd2,0x52,0xa9,0x05,0x49,0x0d,0x2a,0x45,0x2b,0x09,0x56,0x01,0xb5,0x20,0x6d,0x01,0x59,0x69,0xd4,0x0a,0xa8,0x05,0xa9,0x56,0xa5,0x04,0x2b,0x09,0x9e,0x38,0xb6,0x08,0xec,0x74,0x6c,0x05,0xd4,0x0a,0xe4,0x6a,0x52,0x05,0x95,0x0a,0x5a,0x42,0x5b,0x04,0xb6,0x04,0xb4,0x22,0x6a,0x05,0x52,0x75,0xc9,0x0a,0x52,0x05,0x35,0x55,0x4d,0x0a,0x5a,0x02,0x5d,0x31,0xb5,0x02,0x6a,0x8a,0x68,0x05,0xa9,0x0a,0x8a,0x6a,0x2a,0x05,0x2d,0x09,0xaa,0x48,0x5a,0x01,0xb5,0x09,0xb0,0x39,0x64,0x05,0x25,0x75,0x95,0x0a,0x96,0x04,0x4d,0x54,0xad,0x04,0xda,0x04,0xd4,0x44,0xb4,0x05,0x54,0x85,0x52,0x0d,0x92,0x0a,0x56,0x6a,0x56,0x02,0x6d,0x02,0x6a,0x41,0xda,0x02,0xb2,0xa1,0xa9,0x05,0x49,0x0d,0x0a,0x6d,0x2a,0x09,0x56,0x01,0xad,0x50,0x6d,0x01,0xd9,0x02,0xd1,0x3a,0xa8,0x05,0x29,0x85,0xa5,0x0c,0x2a,0x09,0x96,0x54,0xb6,0x08,0x6c,0x09,0x64,0x45,0xd4,0x0a,0xa4,0x05,0x51,0x25,0x95,0x0a,0x2a,0x72,0x5b,0x04,0xb6,0x04,0xac,0x52,0x6a,0x05,0xd2,0x0a,0xa2,0x4a,0x4a,0x05,0x55,0x94,0x2d,0x0a,0x5a,0x02,0x75,0x61,0xb5,0x02,0x6a,0x03,0x61,0x45,0xa9,0x0a,0x4a,0x05,0x25,0x25,0x2d,0x09,0x9a,0x68,0xda,0x08,0xb4,0x09,0xa8,0x59,0x54,0x03,0xa5,0x0a,0x91,0x3a,0x96,0x04,0xad,0xb0,0xad,0x04,0xda,0x04,0xf4,0x62,0xb4,0x05,0x54,0x0b,0x44,0x5d,0x52,0x0a,0x95,0x04,0x55,0x22,0x6d,0x02,0x5a,0x71,0xda,0x02,0xaa,0x05,0xb2,0x55,0x49,0x0b,0x4a,0x0a,0x2d,0x39,0x36,0x01,0x6d,0x80,0x6d,0x01,0xd9,0x02,0xe9,0x6a,0xa8,0x05,0x29,0x0b,0x9a,0x4c,0xaa,0x08,0xb6,0x08,0xb4,0x38,0x6c,0x09,0x54,0x75,0xd4,0x0a,0xa4,0x05,0x45,0x55,0x95,0x0a,0x9a,0x04,0x55,0x44,0xb5,0x04,0x6a,0x82,0x6a,0x05,0xd2,0x0a,0x92,0x6a,0x4a,0x05,0x55,0x0a,0x2a,0x4a,0x5a,0x02,0xb5,0x02,0xb2,0x31,0x69,0x03,0x31,0x73,0xa9,0x0a,0x4a,0x05,0x2d,0x55,0x2d,0x09,0x5a,0x01,0xd5,0x48,0xb4,0x09,0x68,0x89,0x54,0x0b,0xa4,0x0a,0xa5,0x6a,0x95,0x04,0xad,0x08,0x6a,0x44,0xda,0x04,0x74,0x05,0xb0,0x25,0x54,0x03};
|
||||
/** 旬 */
|
||||
public static final String[] XUN = {"甲子","甲戌","甲申","甲午","甲辰","甲寅"};
|
||||
/** 旬空 */
|
||||
public static final String[] XUN_KONG = {"戌亥","申酉","午未","辰巳","寅卯","子丑"};
|
||||
/** 天干 */
|
||||
public static final String[] GAN = {"","甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
|
||||
/** 喜神方位,《喜神方位歌》:甲己在艮乙庚乾,丙辛坤位喜神安. 丁壬只在离宫坐,戊癸原在在巽间。 */
|
||||
@@ -1142,17 +1146,11 @@ public class LunarUtil{
|
||||
public static int nextMonth(int y,int m){
|
||||
int n = Math.abs(m)+1;
|
||||
if(m>0){
|
||||
int index = y-BASE_YEAR+BASE_INDEX;
|
||||
int v = LUNAR_MONTH[2*index+1];
|
||||
v = (v>>4)&0x0F;
|
||||
if(v==m){
|
||||
if(m==getLeapMonth(y)){
|
||||
n = -m;
|
||||
}
|
||||
}
|
||||
if(n==13){
|
||||
n = 1;
|
||||
}
|
||||
return n;
|
||||
return 13!=n?n:1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1450,4 +1448,51 @@ public class LunarUtil{
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取干支所在旬下标,0-5
|
||||
* @param ganZhi 干支
|
||||
* @return 旬下标,0-5
|
||||
*/
|
||||
protected static int getXunIndex(String ganZhi){
|
||||
String gan = ganZhi.substring(0,1);
|
||||
String zhi = ganZhi.substring(1);
|
||||
int ganIndex = 0;
|
||||
int zhiIndex = 0;
|
||||
for(int i=0,j=GAN.length;i<j;i++){
|
||||
if(GAN[i].equals(gan)){
|
||||
ganIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(int i=0,j=ZHI.length;i<j;i++){
|
||||
if(ZHI[i].equals(zhi)){
|
||||
zhiIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int diff = ganIndex - zhiIndex;
|
||||
if(diff<0){
|
||||
diff += 12;
|
||||
}
|
||||
return diff/2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取干支所在旬
|
||||
* @param ganZhi 干支
|
||||
* @return 旬
|
||||
*/
|
||||
public static String getXun(String ganZhi){
|
||||
return XUN[getXunIndex(ganZhi)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取干支所在旬对应的旬空(空亡)
|
||||
* @param ganZhi 干支
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public static String getXunKong(String ganZhi){
|
||||
return XUN_KONG[getXunIndex(ganZhi)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ public class SolarUtil{
|
||||
put("10-13",Collections.nCopies(1,"中国少年先锋队诞辰日"));
|
||||
put("10-25",Collections.nCopies(1,"抗美援朝纪念日"));
|
||||
put("11-12",Collections.nCopies(1,"孙中山诞辰纪念日"));
|
||||
put("11-17",Collections.nCopies(1,"国际大学生节"));
|
||||
put("11-28",Collections.nCopies(1,"恩格斯诞辰纪念日"));
|
||||
put("12-1",Collections.nCopies(1,"世界艾滋病日"));
|
||||
put("12-12",Collections.nCopies(1,"西安事变纪念日"));
|
||||
|
||||
@@ -191,6 +191,15 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(9, yun.getStartMonth());
|
||||
Assert.assertEquals(20, yun.getStartDay());
|
||||
Assert.assertEquals("1973-09-12", yun.getStartSolar().toYmd());
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
Assert.assertEquals(9, yun.getStartYear());
|
||||
Assert.assertEquals(0, yun.getStartMonth());
|
||||
Assert.assertEquals(10, yun.getStartDay());
|
||||
Assert.assertEquals("2001-02-12", yun.getStartSolar().toYmd());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,6 +225,25 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(endAges[i], daYun.getEndAge());
|
||||
Assert.assertEquals(yearGanZhi[i], daYun.getGanZhi());
|
||||
}
|
||||
|
||||
startYears = new int[]{1992, 2001, 2011, 2021, 2031, 2041, 2051, 2061, 2071, 2081};
|
||||
endYears = new int[]{2000, 2010, 2020, 2030, 2040, 2050, 2060, 2070, 2080, 2090};
|
||||
startAges = new int[]{1, 10, 20, 30, 40, 50, 60, 70, 80, 90};
|
||||
endAges = new int[]{9, 19, 29, 39, 49, 59, 69, 79, 89, 99};
|
||||
yearGanZhi = new String[]{"", "庚子", "己亥", "戊戌", "丁酉", "丙申", "乙未", "甲午", "癸巳", "壬辰"};
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
l = yun.getDaYun();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
DaYun daYun = l[i];
|
||||
Assert.assertEquals(startYears[i], daYun.getStartYear());
|
||||
Assert.assertEquals(endYears[i], daYun.getEndYear());
|
||||
Assert.assertEquals(startAges[i], daYun.getStartAge());
|
||||
Assert.assertEquals(endAges[i], daYun.getEndAge());
|
||||
Assert.assertEquals(yearGanZhi[i], daYun.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,6 +278,71 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(years[i] + "年", ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
|
||||
solar = new Solar(1981, 8, 16, 9, 30, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
years = new int[]{1981, 1982, 1983};
|
||||
ages = new int[]{1, 2, 3};
|
||||
ganZhi = new String[]{"辛酉","壬戌","癸亥"};
|
||||
l = daYun[0].getLiuNian();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuNian liuNian = l[i];
|
||||
Assert.assertEquals(years[i], liuNian.getYear());
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
|
||||
years = new int[]{1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993};
|
||||
ages = new int[]{4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
|
||||
ganZhi = new String[]{"甲子","乙丑","丙寅","丁卯","戊辰","己巳","庚午","辛未","壬申","癸酉"};
|
||||
l = daYun[1].getLiuNian();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuNian liuNian = l[i];
|
||||
Assert.assertEquals(years[i], liuNian.getYear());
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
|
||||
solar = new Solar(1981, 8, 8, 1, 30, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
l = daYun[0].getLiuNian();
|
||||
Assert.assertEquals(0, l.length);
|
||||
|
||||
years = new int[]{1981,1982, 1983,1984, 1985, 1986, 1987, 1988, 1989, 1990};
|
||||
ages = new int[]{1,2,3,4,5,6,7,8,9,10};
|
||||
ganZhi = new String[]{"辛酉","壬戌","癸亥","甲子","乙丑","丙寅","丁卯","戊辰","己巳","庚午"};
|
||||
l = daYun[1].getLiuNian();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuNian liuNian = l[i];
|
||||
Assert.assertEquals(years[i], liuNian.getYear());
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
years = new int[]{1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000};
|
||||
ages = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
ganZhi = new String[]{"壬申","癸酉","甲戌", "乙亥", "丙子", "丁丑", "戊寅", "己卯", "庚辰"};
|
||||
l = daYun[0].getLiuNian();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuNian liuNian = l[i];
|
||||
Assert.assertEquals(years[i], liuNian.getYear());
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,6 +377,19 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(ages[i], xiaoYun.getAge());
|
||||
Assert.assertEquals(years[i] + "年", ganZhi[i], xiaoYun.getGanZhi());
|
||||
}
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
ganZhi = new String[]{"丁巳", "丙辰", "乙卯", "甲寅", "癸丑", "壬子","辛亥","庚戌","己酉"};
|
||||
l = daYun[0].getXiaoYun();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
XiaoYun xiaoYun = l[i];
|
||||
Assert.assertEquals(ganZhi[i], xiaoYun.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,6 +418,21 @@ public class BaZiTestNew {
|
||||
LiuYue liuYue = l[i];
|
||||
Assert.assertEquals(ganZhi[i], liuYue.getGanZhi());
|
||||
}
|
||||
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
ganZhi = new String[]{"壬寅", "癸卯", "甲辰", "乙巳", "丙午", "丁未", "戊申", "己酉", "庚戌", "辛亥", "壬子", "癸丑"};
|
||||
liuNian = daYun[0].getLiuNian();
|
||||
l = liuNian[0].getLiuYue();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuYue liuYue = l[i];
|
||||
Assert.assertEquals(ganZhi[i], liuYue.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,33 @@ public class BaZiTest {
|
||||
Assert.assertEquals("时柱", "壬辰", eightChar.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGanZhi2() {
|
||||
Solar solar = new Solar(1988, 2, 15, 23, 30, 0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱", "戊辰", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "甲寅", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "辛丑", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
|
||||
|
||||
solar = new Solar(1988, 2, 15, 22, 30, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱", "戊辰", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "甲寅", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "丁亥", eightChar.getTime());
|
||||
|
||||
solar = new Solar(1988, 2, 2, 22, 30, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱", "丁卯", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "癸丑", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "丁亥", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "辛亥", eightChar.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHideGan() {
|
||||
Solar solar = new Solar(2005, 12, 23, 8, 37, 0);
|
||||
@@ -60,10 +87,90 @@ public class BaZiTest {
|
||||
Solar solar = new Solar(2005, 12, 23, 8, 37, 0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱地势", "临官", eightChar.getYearDiShi());
|
||||
Assert.assertEquals("月柱地势", "长生", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals("日柱地势", "死", eightChar.getDayDiShi());
|
||||
Assert.assertEquals("时柱地势", "墓", eightChar.getTimeDiShi());
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "临官", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "长生", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "死", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "墓", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 18, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "病", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "死", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "衰", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "绝", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 19, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "胎", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "绝", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "长生", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "死", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 20, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "绝", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "胎", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "病", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "长生", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 21, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "胎", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "绝", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "冠带", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "死", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 22, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "绝", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "胎", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "帝旺", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "长生", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 23, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "死", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "病", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "沐浴", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "帝旺", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 24, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "长生", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "沐浴", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "衰", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "临官", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 25, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "帝旺", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "临官", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "长生", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "沐浴", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 26, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "临官", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "帝旺", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "病", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "病", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 27, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "沐浴", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "长生", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "养", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "胎", eightChar.getTimeDiShi());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
33
src/test/java/test/FestivalTest.java
Normal file
33
src/test/java/test/FestivalTest.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Solar;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 节日测试
|
||||
*
|
||||
* @author 6tail
|
||||
*/
|
||||
public class FestivalTest {
|
||||
@Test
|
||||
public void test() {
|
||||
Solar solar = Solar.fromYmd(2020, 11, 26);
|
||||
Assert.assertEquals("[感恩节]", solar.getFestivals() + "");
|
||||
|
||||
solar = Solar.fromYmd(2020, 6, 21);
|
||||
Assert.assertEquals("[父亲节]", solar.getFestivals() + "");
|
||||
|
||||
solar = Solar.fromYmd(2021, 5, 9);
|
||||
Assert.assertEquals("[母亲节]", solar.getFestivals() + "");
|
||||
|
||||
solar = Solar.fromYmd(1986, 11, 27);
|
||||
Assert.assertEquals("[感恩节]", solar.getFestivals() + "");
|
||||
|
||||
solar = Solar.fromYmd(1985, 6, 16);
|
||||
Assert.assertEquals("[父亲节]", solar.getFestivals() + "");
|
||||
|
||||
solar = Solar.fromYmd(1984, 5, 13);
|
||||
Assert.assertEquals("[母亲节]", solar.getFestivals() + "");
|
||||
}
|
||||
}
|
||||
119
src/test/java/test/HolidayTest.java
Normal file
119
src/test/java/test/HolidayTest.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Solar;
|
||||
import com.nlf.calendar.util.HolidayUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HolidayTest {
|
||||
|
||||
@Test
|
||||
public void test2021() {
|
||||
Map<String, String> holidays = new HashMap<String, String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
put("2021-01-01", "2021-01-01 元旦节 2021-01-01");
|
||||
put("2021-01-02", "2021-01-02 元旦节 2021-01-01");
|
||||
put("2021-01-03", "2021-01-03 元旦节 2021-01-01");
|
||||
|
||||
put("2021-02-11", "2021-02-11 春节 2021-02-12");
|
||||
put("2021-02-12", "2021-02-12 春节 2021-02-12");
|
||||
put("2021-02-13", "2021-02-13 春节 2021-02-12");
|
||||
put("2021-02-14", "2021-02-14 春节 2021-02-12");
|
||||
put("2021-02-15", "2021-02-15 春节 2021-02-12");
|
||||
put("2021-02-16", "2021-02-16 春节 2021-02-12");
|
||||
put("2021-02-17", "2021-02-17 春节 2021-02-12");
|
||||
|
||||
put("2021-02-07", "2021-02-07 春节调休 2021-02-12");
|
||||
put("2021-02-20", "2021-02-20 春节调休 2021-02-12");
|
||||
|
||||
put("2021-04-03", "2021-04-03 清明节 2021-04-04");
|
||||
put("2021-04-04", "2021-04-04 清明节 2021-04-04");
|
||||
put("2021-04-05", "2021-04-05 清明节 2021-04-04");
|
||||
|
||||
put("2021-05-01", "2021-05-01 劳动节 2021-05-01");
|
||||
put("2021-05-02", "2021-05-02 劳动节 2021-05-01");
|
||||
put("2021-05-03", "2021-05-03 劳动节 2021-05-01");
|
||||
put("2021-05-04", "2021-05-04 劳动节 2021-05-01");
|
||||
put("2021-05-05", "2021-05-05 劳动节 2021-05-01");
|
||||
|
||||
put("2021-04-25", "2021-04-25 劳动节调休 2021-05-01");
|
||||
put("2021-05-08", "2021-05-08 劳动节调休 2021-05-01");
|
||||
|
||||
put("2021-06-12", "2021-06-12 端午节 2021-06-14");
|
||||
put("2021-06-13", "2021-06-13 端午节 2021-06-14");
|
||||
put("2021-06-14", "2021-06-14 端午节 2021-06-14");
|
||||
|
||||
put("2021-09-19", "2021-09-19 中秋节 2021-09-21");
|
||||
put("2021-09-20", "2021-09-20 中秋节 2021-09-21");
|
||||
put("2021-09-21", "2021-09-21 中秋节 2021-09-21");
|
||||
|
||||
put("2021-09-18", "2021-09-18 中秋节调休 2021-09-21");
|
||||
|
||||
put("2021-10-01", "2021-10-01 国庆节 2021-10-01");
|
||||
put("2021-10-02", "2021-10-02 国庆节 2021-10-01");
|
||||
put("2021-10-03", "2021-10-03 国庆节 2021-10-01");
|
||||
put("2021-10-04", "2021-10-04 国庆节 2021-10-01");
|
||||
put("2021-10-05", "2021-10-05 国庆节 2021-10-01");
|
||||
put("2021-10-06", "2021-10-06 国庆节 2021-10-01");
|
||||
put("2021-10-07", "2021-10-07 国庆节 2021-10-01");
|
||||
|
||||
put("2021-09-26", "2021-09-26 国庆节调休 2021-10-01");
|
||||
put("2021-10-09", "2021-10-09 国庆节调休 2021-10-01");
|
||||
}
|
||||
};
|
||||
Solar solar = Solar.fromYmd(2021, 1, 1);
|
||||
while (solar.toYmd().compareTo("2022-01-01") < 0) {
|
||||
String ymd = solar.toYmd();
|
||||
String holiday = holidays.get(ymd);
|
||||
Assert.assertEquals(ymd, holiday + "", HolidayUtil.getHoliday(ymd) + "");
|
||||
|
||||
solar = solar.next(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Assert.assertEquals("2020-01-01 元旦节 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
|
||||
|
||||
// 将2020-01-01修改为春节
|
||||
HolidayUtil.fix("202001011120200101");
|
||||
Assert.assertEquals("2020-01-01 春节 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
|
||||
|
||||
// 追加2099-01-01为元旦节
|
||||
HolidayUtil.fix("209901010120990101");
|
||||
Assert.assertEquals("2099-01-01 元旦节 2099-01-01", HolidayUtil.getHoliday("2099-01-01") + "");
|
||||
|
||||
// 将2020-01-01修改为春节,并追加2099-01-01为元旦节
|
||||
HolidayUtil.fix("202001011120200101209901010120990101");
|
||||
Assert.assertEquals("2020-01-01 春节 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
|
||||
Assert.assertEquals("2099-01-01 元旦节 2099-01-01", HolidayUtil.getHoliday("2099-01-01") + "");
|
||||
|
||||
// 更改节假日名称
|
||||
String[] names = HolidayUtil.NAMES;
|
||||
names[0] = "元旦";
|
||||
names[1] = "大年初一";
|
||||
|
||||
HolidayUtil.fix(names, null);
|
||||
Assert.assertEquals("2020-01-01 大年初一 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
|
||||
Assert.assertEquals("2099-01-01 元旦 2099-01-01", HolidayUtil.getHoliday("2099-01-01") + "");
|
||||
|
||||
// 追加节假日名称和数据
|
||||
names = new String[12];
|
||||
for (int i = 0, j = HolidayUtil.NAMES.length; i < j; i++) {
|
||||
names[i] = HolidayUtil.NAMES[i];
|
||||
}
|
||||
names[9] = "我的生日";
|
||||
names[10] = "结婚纪念日";
|
||||
names[11] = "她的生日";
|
||||
|
||||
HolidayUtil.fix(names, "20210529912021052920211111:12021111120211201;120211201");
|
||||
Assert.assertEquals("2021-05-29 我的生日 2021-05-29", HolidayUtil.getHoliday("2021-05-29") + "");
|
||||
Assert.assertEquals("2021-11-11 结婚纪念日 2021-11-11", HolidayUtil.getHoliday("2021-11-11") + "");
|
||||
Assert.assertEquals("2021-12-01 她的生日 2021-12-01", HolidayUtil.getHoliday("2021-12-01") + "");
|
||||
}
|
||||
}
|
||||
@@ -154,5 +154,23 @@ public class JieQiTest {
|
||||
Assert.assertEquals("小寒", lunar.getNextJie().getName());
|
||||
Assert.assertEquals("大寒", lunar.getNextQi().getName());
|
||||
Assert.assertEquals("小寒", lunar.getNextJieQi().getName());
|
||||
|
||||
|
||||
solar = Solar.fromYmd(2012,12,25);
|
||||
lunar = solar.getLunar();
|
||||
Assert.assertEquals("", lunar.getJie());
|
||||
Assert.assertEquals("", lunar.getQi());
|
||||
Assert.assertEquals("", lunar.getJieQi());
|
||||
Assert.assertNull(lunar.getCurrentJie());
|
||||
Assert.assertNull(lunar.getCurrentQi());
|
||||
Assert.assertNull(lunar.getCurrentJieQi());
|
||||
|
||||
Assert.assertEquals("小寒", lunar.getNextJie().getName());
|
||||
Assert.assertEquals("大寒", lunar.getNextQi().getName());
|
||||
Assert.assertEquals("小寒", lunar.getNextJieQi().getName());
|
||||
|
||||
Assert.assertEquals("大雪", lunar.getPrevJie().getName());
|
||||
Assert.assertEquals("冬至", lunar.getPrevQi().getName());
|
||||
Assert.assertEquals("冬至", lunar.getPrevJieQi().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Lunar;
|
||||
import com.nlf.calendar.Solar;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -20,4 +21,13 @@ public class LunarTest {
|
||||
Assert.assertEquals("2019-05-01 00:00:00 星期三 (劳动节) 金牛座",date.getSolar().toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNext(){
|
||||
Solar solar = new Solar(2020,1,10,12,0,0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
for(int i=-500;i<500;i++){
|
||||
Assert.assertEquals("推移天数:"+i,solar.next(i).getLunar().toFullString(),lunar.next(i).toFullString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,4 +20,27 @@ public class SolarTest {
|
||||
Assert.assertEquals("二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 (七殿泰山王诞) 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[坎](正北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]",date.getLunar().toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNext(){
|
||||
Solar date = new Solar(2020,1,23);
|
||||
Assert.assertEquals("2020-01-24",date.next(1).toString());
|
||||
// 仅工作日,跨越春节假期
|
||||
Assert.assertEquals("2020-02-03",date.next(1,true).toString());
|
||||
|
||||
date = new Solar(2020,2,3);
|
||||
Assert.assertEquals("2020-01-31",date.next(-3).toString());
|
||||
// 仅工作日,跨越春节假期
|
||||
Assert.assertEquals("2020-01-21",date.next(-3,true).toString());
|
||||
|
||||
date = new Solar(2020,2,9);
|
||||
Assert.assertEquals("2020-02-15",date.next(6).toString());
|
||||
// 仅工作日,跨越周末
|
||||
Assert.assertEquals("2020-02-17",date.next(6,true).toString());
|
||||
|
||||
date = new Solar(2020,1,17);
|
||||
Assert.assertEquals("2020-01-18",date.next(1).toString());
|
||||
// 仅工作日,周日调休按上班算
|
||||
Assert.assertEquals("2020-01-19",date.next(1,true).toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
182
src/test/java/test/XunTest.java
Normal file
182
src/test/java/test/XunTest.java
Normal file
@@ -0,0 +1,182 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.EightChar;
|
||||
import com.nlf.calendar.Lunar;
|
||||
import com.nlf.calendar.Solar;
|
||||
import com.nlf.calendar.util.LunarUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 旬测试
|
||||
*
|
||||
* @author 6tail
|
||||
*/
|
||||
public class XunTest {
|
||||
|
||||
@Test
|
||||
public void testXun(){
|
||||
Map<String,String> xun = new HashMap<String, String>();
|
||||
xun.put("甲子","甲子");
|
||||
xun.put("乙丑","甲子");
|
||||
xun.put("丙寅","甲子");
|
||||
xun.put("丁卯","甲子");
|
||||
xun.put("戊辰","甲子");
|
||||
xun.put("己巳","甲子");
|
||||
xun.put("庚午","甲子");
|
||||
xun.put("辛未","甲子");
|
||||
xun.put("壬申","甲子");
|
||||
xun.put("癸酉","甲子");
|
||||
xun.put("甲戌","甲戌");
|
||||
xun.put("乙亥","甲戌");
|
||||
xun.put("丙子","甲戌");
|
||||
xun.put("丁丑","甲戌");
|
||||
xun.put("戊寅","甲戌");
|
||||
xun.put("己卯","甲戌");
|
||||
xun.put("庚辰","甲戌");
|
||||
xun.put("辛巳","甲戌");
|
||||
xun.put("壬午","甲戌");
|
||||
xun.put("癸未","甲戌");
|
||||
xun.put("甲申","甲申");
|
||||
xun.put("乙酉","甲申");
|
||||
xun.put("丙戌","甲申");
|
||||
xun.put("丁亥","甲申");
|
||||
xun.put("戊子","甲申");
|
||||
xun.put("己丑","甲申");
|
||||
xun.put("庚寅","甲申");
|
||||
xun.put("辛卯","甲申");
|
||||
xun.put("壬辰","甲申");
|
||||
xun.put("癸巳","甲申");
|
||||
xun.put("甲午","甲午");
|
||||
xun.put("乙未","甲午");
|
||||
xun.put("丙申","甲午");
|
||||
xun.put("丁酉","甲午");
|
||||
xun.put("戊戌","甲午");
|
||||
xun.put("己亥","甲午");
|
||||
xun.put("庚子","甲午");
|
||||
xun.put("辛丑","甲午");
|
||||
xun.put("壬寅","甲午");
|
||||
xun.put("癸卯","甲午");
|
||||
xun.put("甲辰","甲辰");
|
||||
xun.put("乙巳","甲辰");
|
||||
xun.put("丙午","甲辰");
|
||||
xun.put("丁未","甲辰");
|
||||
xun.put("戊申","甲辰");
|
||||
xun.put("己酉","甲辰");
|
||||
xun.put("庚戌","甲辰");
|
||||
xun.put("辛亥","甲辰");
|
||||
xun.put("壬子","甲辰");
|
||||
xun.put("癸丑","甲辰");
|
||||
xun.put("甲寅","甲寅");
|
||||
xun.put("乙卯","甲寅");
|
||||
xun.put("丙辰","甲寅");
|
||||
xun.put("丁巳","甲寅");
|
||||
xun.put("戊午","甲寅");
|
||||
xun.put("己未","甲寅");
|
||||
xun.put("庚申","甲寅");
|
||||
xun.put("辛酉","甲寅");
|
||||
xun.put("壬戌","甲寅");
|
||||
xun.put("癸亥","甲寅");
|
||||
|
||||
for(Map.Entry<String,String> entry:xun.entrySet()){
|
||||
Assert.assertEquals(entry.getValue(), LunarUtil.getXun(entry.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXunKong(){
|
||||
Map<String,String> kong = new HashMap<String, String>();
|
||||
kong.put("甲子","戌亥");
|
||||
kong.put("乙丑","戌亥");
|
||||
kong.put("丙寅","戌亥");
|
||||
kong.put("丁卯","戌亥");
|
||||
kong.put("戊辰","戌亥");
|
||||
kong.put("己巳","戌亥");
|
||||
kong.put("庚午","戌亥");
|
||||
kong.put("辛未","戌亥");
|
||||
kong.put("壬申","戌亥");
|
||||
kong.put("癸酉","戌亥");
|
||||
kong.put("甲戌","申酉");
|
||||
kong.put("乙亥","申酉");
|
||||
kong.put("丙子","申酉");
|
||||
kong.put("丁丑","申酉");
|
||||
kong.put("戊寅","申酉");
|
||||
kong.put("己卯","申酉");
|
||||
kong.put("庚辰","申酉");
|
||||
kong.put("辛巳","申酉");
|
||||
kong.put("壬午","申酉");
|
||||
kong.put("癸未","申酉");
|
||||
kong.put("甲申","午未");
|
||||
kong.put("乙酉","午未");
|
||||
kong.put("丙戌","午未");
|
||||
kong.put("丁亥","午未");
|
||||
kong.put("戊子","午未");
|
||||
kong.put("己丑","午未");
|
||||
kong.put("庚寅","午未");
|
||||
kong.put("辛卯","午未");
|
||||
kong.put("壬辰","午未");
|
||||
kong.put("癸巳","午未");
|
||||
kong.put("甲午","辰巳");
|
||||
kong.put("乙未","辰巳");
|
||||
kong.put("丙申","辰巳");
|
||||
kong.put("丁酉","辰巳");
|
||||
kong.put("戊戌","辰巳");
|
||||
kong.put("己亥","辰巳");
|
||||
kong.put("庚子","辰巳");
|
||||
kong.put("辛丑","辰巳");
|
||||
kong.put("壬寅","辰巳");
|
||||
kong.put("癸卯","辰巳");
|
||||
kong.put("甲辰","寅卯");
|
||||
kong.put("乙巳","寅卯");
|
||||
kong.put("丙午","寅卯");
|
||||
kong.put("丁未","寅卯");
|
||||
kong.put("戊申","寅卯");
|
||||
kong.put("己酉","寅卯");
|
||||
kong.put("庚戌","寅卯");
|
||||
kong.put("辛亥","寅卯");
|
||||
kong.put("壬子","寅卯");
|
||||
kong.put("癸丑","寅卯");
|
||||
kong.put("甲寅","子丑");
|
||||
kong.put("乙卯","子丑");
|
||||
kong.put("丙辰","子丑");
|
||||
kong.put("丁巳","子丑");
|
||||
kong.put("戊午","子丑");
|
||||
kong.put("己未","子丑");
|
||||
kong.put("庚申","子丑");
|
||||
kong.put("辛酉","子丑");
|
||||
kong.put("壬戌","子丑");
|
||||
kong.put("癸亥","子丑");
|
||||
|
||||
for(Map.Entry<String,String> entry:kong.entrySet()){
|
||||
Assert.assertEquals(entry.getValue(), LunarUtil.getXunKong(entry.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXun1(){
|
||||
Solar solar = new Solar(2020,11,19,0,0,0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("甲午",lunar.getYearXun());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXunKong1(){
|
||||
Solar solar = new Solar(2020,11,19,0,0,0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("辰巳",lunar.getYearXunKong());
|
||||
Assert.assertEquals("午未",lunar.getMonthXunKong());
|
||||
Assert.assertEquals("戌亥",lunar.getDayXunKong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaZiDayXunKong(){
|
||||
Solar solar = new Solar(1990,12,23,8,37,0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("子丑",eightChar.getDayXunKong());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user