1
0
mirror of synced 2026-10-20 05:26:12 +08:00

optimized codes and fix negative month bug @ Lunar.getXiu()

This commit is contained in:
6tail
2019-05-05 15:45:00 +08:00
parent c196e58ec8
commit 6db884b981
16 changed files with 366 additions and 109 deletions

View File

@@ -7,7 +7,7 @@ import java.util.List;
/**
* 阳历年
*
*
* @author 6tail
*
*/
@@ -15,6 +15,9 @@ public class SolarYear{
/** 年 */
private int year;
/** 一年的月数 */
public static final int MONTH_COUNT = 12;
/**
* 默认当年
*/
@@ -40,7 +43,7 @@ public class SolarYear{
/**
* 通过年初始化
*
*
* @param year 年
*/
public SolarYear(int year){
@@ -79,7 +82,7 @@ public class SolarYear{
/**
* 获取年
*
*
* @return 年
*/
public int getYear(){
@@ -88,19 +91,19 @@ public class SolarYear{
/**
* 获取本年的阳历月列表
*
*
* @return 阳历月列表
*/
public List<SolarMonth> getMonths(){
List<SolarMonth> l = new ArrayList<SolarMonth>(12);
List<SolarMonth> l = new ArrayList<SolarMonth>(MONTH_COUNT);
SolarMonth m = new SolarMonth(year,1);
l.add(m);
for(int i = 1;i<12;i++){
for(int i = 1;i<MONTH_COUNT;i++){
l.add(m.next(i));
}
return l;
}
/**
* 获取往后推几年的阳历年,如果要往前推,则年数用负数
* @param years 年数
@@ -108,11 +111,12 @@ public class SolarYear{
*/
public SolarYear next(int years){
Calendar c = Calendar.getInstance();
c.set(year,0,1);
c.set(year,Calendar.JANUARY,1);
c.add(Calendar.YEAR,years);
return new SolarYear(c);
}
@Override
public String toString(){
return year+"";
}
@@ -120,4 +124,4 @@ public class SolarYear{
public String toFullString(){
return year+"年";
}
}
}