Skip to content

Commit

Permalink
v1.2.13 新增道历Tao。
Browse files Browse the repository at this point in the history
  • Loading branch information
6tail committed Nov 25, 2021
1 parent 868aaac commit bab0529
Show file tree
Hide file tree
Showing 11 changed files with 438 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# lunar [![License](https://img.shields.io/badge/license-MIT-4EB1BA.svg?style=flat-square)](https://github.com/6tail/lunar-java/blob/master/LICENSE)

lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)工具,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶、法定节假日及调休等。
lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)、道历、佛历工具,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶、法定节假日及调休等。

> 支持java 1.5及以上版本。
Expand All @@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.12</version>
<version>1.2.13</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.12</version>
<version>1.2.13</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<packaging>jar</packaging>
<version>1.2.12</version>
<version>1.2.13</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>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/nlf/calendar/Foto.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public static Foto fromLunar(Lunar lunar) {
return new Foto(lunar);
}

public static Foto fromYmdHms(int lunarYear, int lunarMonth, int lunarDay, int hour, int minute, int second) {
return Foto.fromLunar(Lunar.fromYmdHms(lunarYear + DEAD_YEAR - 1, lunarMonth, lunarDay, hour, minute, second));
public static Foto fromYmdHms(int year, int month, int day, int hour, int minute, int second) {
return Foto.fromLunar(Lunar.fromYmdHms(year + DEAD_YEAR - 1, month, day, hour, minute, second));
}

public static Foto fromYmd(int lunarYear, int lunarMonth, int lunarDay) {
return fromYmdHms(lunarYear, lunarMonth, lunarDay, 0, 0, 0);
public static Foto fromYmd(int year, int month, int day) {
return fromYmdHms(year, month, day, 0, 0, 0);
}

public Lunar getLunar() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/nlf/calendar/FotoFestival.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public String getRemark() {

@Override
public String toString() {
return name;
}

public String toFullString() {
StringBuilder s = new StringBuilder();
s.append(name);
if (null != result && result.length() > 0) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/nlf/calendar/Lunar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2690,4 +2690,13 @@ public Foto getFoto() {
return Foto.fromLunar(this);
}

/**
* 获取道历
*
* @return 佛历
*/
public Tao getTao() {
return Tao.fromLunar(this);
}

}
161 changes: 161 additions & 0 deletions src/main/java/com/nlf/calendar/Tao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.nlf.calendar;

import com.nlf.calendar.util.LunarUtil;
import com.nlf.calendar.util.TaoUtil;

import java.util.ArrayList;
import java.util.List;

/**
* 道历
*
* @author 6tail
*/
public class Tao {

public static final int BIRTH_YEAR = -2697;

/**
* 阴历
*/
private Lunar lunar;

public Tao(Lunar lunar) {
this.lunar = lunar;
}

public static Tao fromLunar(Lunar lunar) {
return new Tao(lunar);
}

public static Tao fromYmdHms(int year, int month, int day, int hour, int minute, int second) {
return Tao.fromLunar(Lunar.fromYmdHms(year + BIRTH_YEAR, month, day, hour, minute, second));
}

public static Tao fromYmd(int year, int month, int day) {
return fromYmdHms(year, month, day, 0, 0, 0);
}

public Lunar getLunar() {
return lunar;
}

public int getYear() {
return lunar.getYear() - BIRTH_YEAR;
}

public int getMonth() {
return lunar.getMonth();
}

public int getDay() {
return lunar.getDay();
}

public String getYearInChinese() {
String y = getYear() + "";
StringBuilder s = new StringBuilder();
for (int i = 0, j = y.length(); i < j; i++) {
s.append(LunarUtil.NUMBER[y.charAt(i) - '0']);
}
return s.toString();
}

public String getMonthInChinese() {
return lunar.getMonthInChinese();
}

public String getDayInChinese() {
return lunar.getDayInChinese();
}

public List<TaoFestival> getFestivals() {
List<TaoFestival> l = new ArrayList<TaoFestival>();
List<TaoFestival> fs = TaoUtil.FESTIVAL.get(getMonth() + "-" + getDay());
if (null != fs) {
l.addAll(fs);
}
String jq = lunar.getJieQi();
if ("冬至".equals(jq)) {
l.add(new TaoFestival("元始天尊圣诞"));
} else if ("夏至".equals(jq)) {
l.add(new TaoFestival("灵宝天尊圣诞"));
}
// 八节日
String f = TaoUtil.BA_JIE.get(jq);
if (null != f) {
l.add(new TaoFestival(f));
}
// 八会日
f = TaoUtil.BA_HUI.get(lunar.getDayInGanZhi());
if (null != f) {
l.add(new TaoFestival(f));
}
return l;
}

private boolean isDayIn(String[] days) {
String md = getMonth() + "-" + getDay();
for (String d : days) {
if (md.equals(d)) {
return true;
}
}
return false;
}

/**
* 是否三会日
*
* @return true/false
*/
public boolean isDaySanHui() {
return isDayIn(TaoUtil.SAN_HUI);
}

/**
* 是否三元日
*
* @return true/false
*/
public boolean isDaySanYuan() {
return isDayIn(TaoUtil.SAN_YUAN);
}

/**
* 是否八节日
*
* @return true/false
*/
public boolean isDayBaJie() {
return TaoUtil.BA_JIE.containsKey(lunar.getJieQi());
}

/**
* 是否五腊日
*
* @return true/false
*/
public boolean isDayWuLa() {
return isDayIn(TaoUtil.WU_LA);
}

/**
* 是否八会日
*
* @return true/false
*/
public boolean isDayBaHui() {
return TaoUtil.BA_HUI.containsKey(lunar.getDayInGanZhi());
}

@Override
public String toString() {
return String.format("%s年%s月%s", getYearInChinese(), getMonthInChinese(), getDayInChinese());
}

public String toFullString() {
return String.format("道歷%s年,天運%s年,%s月,%s日。%s月%s日,%s時。", getYearInChinese(), lunar.getYearInGanZhi(), lunar.getMonthInGanZhi(), lunar.getDayInGanZhi(), getMonthInChinese(), getDayInChinese(), lunar.getTimeZhi());
}

}
52 changes: 52 additions & 0 deletions src/main/java/com/nlf/calendar/TaoFestival.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.nlf.calendar;

/**
* 道历节日
*
* @author 6tail
*/
public class TaoFestival {

/**
* 名称
*/
private String name;

/**
* 备注
*/
private String remark;

public TaoFestival(String name, String remark) {
this.name = name;
this.remark = null == remark ? "" : remark;
}

public TaoFestival(String name) {
this(name, null);
}

public String getName() {
return name;
}

public String getRemark() {
return remark;
}

@Override
public String toString() {
return name;
}

public String toFullString() {
StringBuilder s = new StringBuilder();
s.append(name);
if (null != remark && remark.length() > 0) {
s.append("[");
s.append(remark);
s.append("]");
}
return s.toString();
}
}
Loading

0 comments on commit bab0529

Please sign in to comment.