package test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class yearTest {
public static void main(String[] args) throws ParseException {
String hz = "week";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String start_time ="2020-10-02 02:24:00";
String end_time ="2020-10-02 18:59:00";
Date _fzstarttime = dateFormat.parse(start_time);
Date _fzsendtime1 = dateFormat.parse(end_time);
String[] strstart_0= new SimpleDateFormat("yyyy-MM-dd").format(_fzstarttime).toString().split("-");
Integer.parseInt(strstart_0[2]);
String[] strstart = new SimpleDateFormat("HH:mm:ss").format(_fzstarttime).toString().split(":");
Integer.parseInt(strstart[0]);
Integer.parseInt(strstart[1]);
Integer.parseInt(strstart[2]);
String[] strend_0= new SimpleDateFormat("yyyy-MM-dd").format(_fzsendtime1).toString().split("-");
String[] strend = new SimpleDateFormat("HH:mm:ss").format(_fzsendtime1).toString().split(":");
Integer.parseInt(strend_0[2]);
Integer.parseInt(strend[0]);
Integer.parseInt(strend[1]);
Integer.parseInt(strend[2]);
String fzstarttime ="2020-09-01 04:24:00";
String fzsendtime ="2020-11-30 20:53:00";
Date hztime = dateFormat.parse(fzstarttime);
String[] strNow1 = new SimpleDateFormat("yyyy-MM-dd").format(hztime).toString().split("-");
Integer.parseInt(strNow1[0]);
Integer.parseInt(strNow1[1]);
Integer.parseInt(strNow1[2]);
System.out.println(yearTest.getTime(strNow1, strstart, strend, fzsendtime, hz,_fzstarttime));
}
public static List<Map<String,Object>> getTime(String[] strNow1,String[] strstart,String [] strend,String fzsendtime,String hz,Date _fzstarttime){
List<Map<String,Object>> list = new ArrayList<>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.setTime(_fzstarttime);
int Nowtime = cal.get(Calendar.DAY_OF_WEEK)-1;
if(Nowtime==0)Nowtime=7;
System.out.println(Nowtime);
int HzNow =0;
cal.set(Calendar.YEAR,Integer.parseInt(strNow1[0]));
cal.set(Calendar.MONTH,Integer.parseInt(strNow1[1])-1);
cal.set(Calendar.DATE,Integer.parseInt(strNow1[2]));
int i=0;
while(true){
i++;
Map map = new HashMap();
map.put("id", IdGen.uuid());
cal.set(Calendar.HOUR_OF_DAY,Integer.parseInt(strstart[0]));
cal.set(Calendar.MINUTE,Integer.parseInt(strstart[1]));
cal.set(Calendar.SECOND, Integer.parseInt(strstart[2]));
map.put("start_time",dateFormat.format(cal.getTime()));
cal.set(Calendar.HOUR_OF_DAY,Integer.parseInt(strend[0]));
cal.set(Calendar.MINUTE,Integer.parseInt(strend[1]));
cal.set(Calendar.SECOND, Integer.parseInt(strend[2]));
map.put("end_time",dateFormat.format(cal.getTime()));
int flag = dateFormat.format(cal.getTime()).compareTo(fzsendtime);
if(flag>0){
break;
}
if(hz.equals("day")) {
cal.add(Calendar.DATE, 1);
}
if(hz.equals("towday")) {
cal.add(Calendar.DATE, 2);
}
if(hz.equals("week")&&HzNow==0) {
HzNow = cal.get(Calendar.DAY_OF_WEEK)-1;
if(HzNow!=0) {
cal.add(Calendar.DATE, Math.abs(Nowtime - HzNow));
}
HzNow =99;
continue;
}else if(hz.equals("week")&&HzNow!=0) {
cal.add(Calendar.WEEK_OF_MONTH, 1);
}
if(hz.equals("month")) {
cal.add(Calendar.MONTH, 1);
}
list.add(map);
}
return list;
}
}