public ArrayList<CalcPeriod> getCalcPeriods() {
DateTime now = DateTime.now();
DateTime.Property year = now.year();
DateTimeFormatter yyyyMMdd = DateTimeFormat.forPattern("yyyyMMdd");
DateTime season1 = DateTime.parse(year.get() + Constant.SEASON1,yyyyMMdd);
DateTime season2 = DateTime.parse(year.get() + Constant.SEASON2,yyyyMMdd);
DateTime season3 = DateTime.parse(year.get() + Constant.SEASON3,yyyyMMdd);
DateTime season4 = DateTime.parse(year.get() + Constant.SEASON4,yyyyMMdd);
//2.1 今年
ArrayList<CalcPeriod> currentYearList = new ArrayList<>();
if (now.isBefore(season1)){
}else if (now.isAfter(season1) && now.isBefore(season2)){
currentYearList.add(new CalcPeriod(year.get(),"1"));
}else if (now.isAfter(season2) && now.isBefore(season3)) {
currentYearList.add(new CalcPeriod(year.get(), "2"));
}else if (now.isAfter(season3) && now.isBefore(season4)) {
currentYearList.add(new CalcPeriod(year.get(), "3"));
}
//2.2 去年
ArrayList<CalcPeriod> beforeCurrentYearList = new ArrayList<>();
for (int i = 2012; i <= year.get() - 1; i++){
for (int j = 1; j <= 4; j++){
beforeCurrentYearList.add(new CalcPeriod(i, String.valueOf(j)));
}
}
ArrayList<CalcPeriod> totalList = new ArrayList<>();
totalList.addAll(currentYearList);
totalList.addAll(beforeCurrentYearList);
return totalList;
}
public class CalcPeriod
{
private int year;
private String period;
public CalcPeriod(int year, String period) {
this.year = year;
this.period = period;
}
public CalcPeriod() {
}
public int getYear()
{
return this.year;
}
public void setYear(int year) {
this.year = year;
}
}
public static final String SEASON1 = "0331";
public static final String SEASON2 = "0630";
public static final String SEASON3 = "0930";
public static final String SEASON4 = "1231";