Skip to content

Commit

Permalink
v1.2.8 新增佛历Foto;更改Lunar中的getOtherFestivals方法为传统节日。
Browse files Browse the repository at this point in the history
  • Loading branch information
6tail committed Oct 29, 2021
1 parent a783dbd commit d9d7182
Show file tree
Hide file tree
Showing 11 changed files with 555 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.7</version>
<version>1.2.8</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.7</version>
<version>1.2.8</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.7</version>
<version>1.2.8</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
147 changes: 147 additions & 0 deletions src/main/java/com/nlf/calendar/Foto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.nlf.calendar;

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

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

/**
* 佛历
*
* @author 6tail
*/
public class Foto {

public static final int DEAD_YEAR = -543;

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

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

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 fromYmd(int lunarYear, int lunarMonth, int lunarDay) {
return fromYmdHms(lunarYear, lunarMonth, lunarDay, 0, 0, 0);
}

public Lunar getLunar() {
return lunar;
}

public int getYear() {
int sy = lunar.getSolar().getYear();
int y = sy - DEAD_YEAR;
if (sy == lunar.getYear()) {
y++;
}
return y;
}

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<FotoFestival> getFestivals() {
List<FotoFestival> l = new ArrayList<FotoFestival>();
List<FotoFestival> fs = FotoUtil.FESTIVAL.get(getMonth() + "-" + getDay());
if (null != fs) {
l.addAll(fs);
}
return l;
}

public boolean isMonthZhai() {
int m = getMonth();
return 1 == m || 5 == m || 9 == m;
}

public boolean isDayYangGong() {
for (FotoFestival f : getFestivals()) {
if ("杨公忌".equals(f.getName())) {
return true;
}
}
return false;
}

public boolean isDayZhaiShuoWang() {
int d = getDay();
return 1 == d || 15 == d;
}

public boolean isDayZhaiSix() {
int d = getDay();
if (8 == d || 14 == d || 15 == d || 23 == d || 29 == d || 30 == d) {
return true;
} else if (28 == d) {
LunarMonth m = LunarMonth.fromYm(lunar.getYear(), getMonth());
return null != m && 30 != m.getDayCount();
}
return false;
}

public boolean isDayZhaiTen() {
int d = getDay();
return 1 == d || 8 == d || 14 == d || 15 == d || 18 == d || 23 == d || 24 == d || 28 == d || 29 == d || 30 == d;
}

public boolean isDayZhaiGuanYin() {
String k = getMonth() + "-" + getDay();
for (String d : FotoUtil.DAY_ZHAI_GUAN_YIN) {
if (k.equals(d)) {
return true;
}
}
return false;
}

@Override
public String toString() {
return getYearInChinese() + "年" + getMonthInChinese() + "月" + getDayInChinese();
}

public String toFullString() {
StringBuilder s = new StringBuilder();
s.append(toString());
for (FotoFestival f : getFestivals()) {
s.append(" (");
s.append(f);
s.append(")");
}
return s.toString();
}

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

/**
* 佛历因果犯忌
*
* @author 6tail
*/
public class FotoFestival {

/**
* 是日何日,如:雷斋日
*/
private String name;

/**
* 犯之因果,如:犯者夺纪
*/
private String result;

/**
* 是否每月同
*/
private boolean everyMonth;

/**
* 备注,如:宜先一日即戒
*/
private String remark;

public FotoFestival(String name, String result, boolean everyMonth, String remark) {
this.name = name;
this.result = null == result ? "" : result;
this.everyMonth = everyMonth;
this.remark = null == remark ? "" : remark;
}

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

public FotoFestival(String name, String result) {
this(name, result, false);
}

public FotoFestival(String name, String result, boolean everyMonth) {
this(name, result, everyMonth, null);
}

public String getName() {
return name;
}

public String getResult() {
return result;
}

public boolean isEveryMonth() {
return everyMonth;
}

public String getRemark() {
return remark;
}

@Override
public String toString() {
StringBuilder s = new StringBuilder();
s.append(name);
if (null != result && result.length() > 0) {
s.append(" ");
s.append(result);
}
if (null != remark && remark.length() > 0) {
s.append(" ");
s.append(remark);
}
return s.toString();
}
}
14 changes: 13 additions & 1 deletion src/main/java/com/nlf/calendar/Lunar.java
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ public String getTimeShengXiao() {
* @return 中文年,如二零零一
*/
public String getYearInChinese() {
String y = (year + "");
String y = year + "";
StringBuilder s = new StringBuilder();
for (int i = 0, j = y.length(); i < j; i++) {
s.append(LunarUtil.NUMBER[y.charAt(i) - '0']);
Expand Down Expand Up @@ -980,6 +980,9 @@ public List<String> getOtherFestivals() {
if (null != fs) {
l.addAll(fs);
}
if(solar.toYmd().equals(jieQi.get("清明").next(-1).toYmd())) {
l.add("寒食节");
}
return l;
}

Expand Down Expand Up @@ -2642,4 +2645,13 @@ public List<LunarTime> getTimes() {
return l;
}

/**
* 获取佛历
*
* @return 佛历
*/
public Foto getFoto() {
return Foto.fromLunar(this);
}

}
Loading

0 comments on commit d9d7182

Please sign in to comment.