timeslot

TimeIntervalBean


package com.test;



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

public class TimeIntervalBean{
private Calendar currentCalendar;
private Calendar initialTimeCalendar;
private Calendar terminalTimeCalendar;
private Boolean isWeekendToday = Boolean.FALSE;
private Boolean isWeekendNextday = Boolean.FALSE;
private Calendar initialTimeCalendarNextday;
private Calendar terminalTimeCalendarNextday;
private Calendar endTimeCalendar;
private int field;
private int roundInterval;
private int firstTimeInterval;
private int subTimeInterval;
private List startTimeList = new ArrayList();
private List endTimeList = new ArrayList();

public int getSubTimeInterval() {
return subTimeInterval;
}
public void setSubTimeInterval(int subTimeInterval) {
this.subTimeInterval = subTimeInterval;
}
public Calendar getCurrentCalendar() {
return currentCalendar;
}
public void setCurrentCalendar(Calendar currentCalendar) {
this.currentCalendar = currentCalendar;
}
public Calendar getInitialTimeCalendar() {
return initialTimeCalendar;
}
public void setInitialTimeCalendar(Calendar initialTimeCalendar) {
this.initialTimeCalendar = initialTimeCalendar;
}
public Calendar getTerminalTimeCalendar() {
return terminalTimeCalendar;
}
public void setTerminalTimeCalendar(Calendar terminalTimeCalendar) {
this.terminalTimeCalendar = terminalTimeCalendar;
}
public Calendar getEndTimeCalendar() {
return endTimeCalendar;
}
public void setEndTimeCalendar(Calendar endTimeCalendar) {
this.endTimeCalendar = endTimeCalendar;
}
public int getField() {
return field;
}
public void setField(int field) {
this.field = field;
}
public int getRoundInterval() {
return roundInterval;
}
public void setRoundInterval(int roundInterval) {
this.roundInterval = roundInterval;
}
public int getFirstTimeInterval() {
return firstTimeInterval;
}
public void setFirstTimeInterval(int firstTimeInterval) {
this.firstTimeInterval = firstTimeInterval;
}
public List getStartTimeList() {
return startTimeList;
}
public void setStartTimeList(List startTimeList) {
this.startTimeList = startTimeList;
}
public List getEndTimeList() {
return endTimeList;
}
public void setEndTimeList(List endTimeList) {
this.endTimeList = endTimeList;
}
public Boolean getIsWeekendToday() {
return isWeekendToday;
}
public void setIsWeekendToday(Boolean isWeekendToday) {
this.isWeekendToday = isWeekendToday;
}
public Boolean getIsWeekendNextday() {
return isWeekendNextday;
}
public void setIsWeekendNextday(Boolean isWeekendNextday) {
this.isWeekendNextday = isWeekendNextday;
}
public Calendar getInitialTimeCalendarNextday() {
return initialTimeCalendarNextday;
}
public void setInitialTimeCalendarNextday(Calendar initialTimeCalendarNextday) {
this.initialTimeCalendarNextday = initialTimeCalendarNextday;
}
public Calendar getTerminalTimeCalendarNextday() {
return terminalTimeCalendarNextday;
}
public void setTerminalTimeCalendarNextday(Calendar terminalTimeCalendarNextday) {
this.terminalTimeCalendarNextday = terminalTimeCalendarNextday;
}

}



ClickToCallBean


 
package com.test;

import java.util.List;

public class ClickToCallBean {

private String subBusiness;

private String timeZone;

private String customerNumber;

private String preferLanguage;

private List preferLanguageList;

private String countryCode;

private String areaCode;

private String phoneNumber;

private String extensionNumber;

private Boolean isCusomterMobile;

private String enquirySubject;

private List enquirySubjectList;

private String enquiryDetails;

private String callBackTime;

private List callBackTimeList;

private String callBackStartTime;

private String callBackEndTime;

private List startTimeList;

private List endTimeList;

private String confirmNumber;

private Boolean hasErrorFlag = Boolean.FALSE;

public String getTimeZone() {
return timeZone;
}

public void setTimeZone(String timeZone) {
if (timeZone != null) {
this.timeZone = timeZone ;
}
}

public String getCustomerNumber() {
return customerNumber;
}

public void setCustomerNumber(String customerNumber) {
this.customerNumber = customerNumber ;


}

public String getPreferLanguage() {
return preferLanguage;
}

public void setPreferLanguage(String preferLanguage) {
this.preferLanguage = preferLanguage ;

}

public List getPreferLanguageList() {
return preferLanguageList;
}

public void setPreferLanguageList(List preferLanguageList) {
this.preferLanguageList = preferLanguageList;
}

public String getCountryCode() {
return countryCode;
}

public void setCountryCode(String countryCode) {
this.countryCode = countryCode ;

}

public String getAreaCode() {
return areaCode;
}

public void setAreaCode(String areaCode) {
this.areaCode = areaCode ;

}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber ;

}

public String getExtensionNumber() {
return extensionNumber;
}

public void setExtensionNumber(String extensionNumber) {
this.extensionNumber = extensionNumber ;

}

public Boolean getIsCusomterMobile() {
return isCusomterMobile;
}

public void setIsCusomterMobile(Boolean isCusomterMobile) {
this.isCusomterMobile = isCusomterMobile;
}

public String getEnquirySubject() {
return enquirySubject;
}

public void setEnquirySubject(String enquirySubject) {
this.enquirySubject = enquirySubject ;

}

public List getEnquirySubjectList() {
return enquirySubjectList;
}

public void setEnquirySubjectList(List enquirySubjectList) {
this.enquirySubjectList = enquirySubjectList;
}

public String getEnquiryDetails() {
return enquiryDetails;
}

public void setEnquiryDetails(String enquiryDetails) {
this.enquiryDetails = enquiryDetails ;

}

public String getCallBackTime() {
return callBackTime;
}

public void setCallBackTime(String callBackTime) {
this.callBackTime = callBackTime ;

}

public List getCallBackTimeList() {
return callBackTimeList;
}

public void setCallBackTimeList(List callBackTimeList) {
this.callBackTimeList = callBackTimeList;
}

public String getCallBackStartTime() {
return callBackStartTime;
}

public void setCallBackStartTime(String callBackStartTime) {
this.callBackStartTime = callBackStartTime ;

}

public String getCallBackEndTime() {
return callBackEndTime;
}

public void setCallBackEndTime(String callBackEndTime) {
this.callBackEndTime = callBackEndTime ;

}

public String getConfirmNumber() {
return confirmNumber;
}

public void setConfirmNumber(String confirmNumber) {
this.confirmNumber = confirmNumber ;
}


public Boolean getHasErrorFlag() {
return hasErrorFlag;
}

public void setHasErrorFlag(Boolean hasErrorFlag) {
this.hasErrorFlag = hasErrorFlag;
}

public List getStartTimeList() {
return startTimeList;
}

public void setStartTimeList(List startTimeList) {
this.startTimeList = startTimeList;
}

public List getEndTimeList() {
return endTimeList;
}

public void setEndTimeList(List endTimeList) {
this.endTimeList = endTimeList;
}

public String getSubBusiness() {
return subBusiness;
}

public void setSubBusiness(String subBusiness) {
this.subBusiness = subBusiness ;
}

}



Test


package com.test.change;




import java.text.ParseException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;

public class Test {
public static void generateCallBackTimeList() throws ParseException{
Calendar cal =Calendar.getInstance();

TimeIntervalBean timeIntervalBean = new TimeIntervalBean();
ClickToCallBean ctcBean = new ClickToCallBean();
timeIntervalBean.setField(Calendar.MINUTE);
timeIntervalBean.setRoundInterval(30);
timeIntervalBean.setFirstTimeInterval(30);
timeIntervalBean.setSubTimeInterval(30);
String saturdayInitialTime = "00:00";
String saturdayTerminalTime = "24:00";
String saturdayInitialTimeArray[] = saturdayInitialTime.split(":");
String saturdayTerminalTimeArray[] = saturdayTerminalTime.split(":");

String sundayInitialTime = "06:00";
String sundayTerminalTime = "24:00";
String sundayInitialTimeArray[] = sundayInitialTime.split(":");
String sundayTerminalTimeArray[] = sundayTerminalTime.split(":");


String initialTime = "00:00";
String terminalTime = "24:00";
String initialTimeArray[] = initialTime.split(":");
String terminalTimeArray[] = terminalTime.split(":");
TimeZone timeZone=cal.getTimeZone();
TimeZone.setDefault(timeZone);
ctcBean.setTimeZone(timeZone.getID());
Calendar currentCalendar = Calendar.getInstance(timeZone);


// String noServiceDate="7,1";
//
//
// String []noServiceDateArray=null;
// if( noServiceDate!=null || !"".equals(noServiceDate)){
// noServiceDateArray =noServiceDate.split(",");//1 7
// }
//

// TimeZone timeZone = businessUnit.getToolkit().getDateTimeFormatter().getCurrentCalendar((Locale)baseProfile.getProperty(BaseProfile.LOCALE), true).getTimeZone();
// TimeZone.setDefault(timeZone);
int initialTimeHour = Integer.valueOf(initialTimeArray[0]).intValue();
int initialTimeMinutes = Integer.valueOf(initialTimeArray[1]).intValue();
int terminalTimeHour = Integer.valueOf(terminalTimeArray[0]).intValue();
int terminalTimeMinutes = Integer.valueOf(terminalTimeArray[1]).intValue();

// Arrays.binarySearch(noServiceDateArray, dayOfWeek)>=0
if(String.valueOf(currentCalendar.get(Calendar.DAY_OF_WEEK)).equals("6")){
System.out.println("11111111");
initialTimeHour = Integer.valueOf(saturdayInitialTimeArray[0]).intValue();
initialTimeMinutes = Integer.valueOf(saturdayInitialTimeArray[1]).intValue();
terminalTimeHour = Integer.valueOf(saturdayTerminalTimeArray[0]).intValue();
terminalTimeMinutes = Integer.valueOf(saturdayTerminalTimeArray[1]).intValue();
}

if(String.valueOf(currentCalendar.get(Calendar.DAY_OF_WEEK)).equals("7")){
System.out.println("222222222");
initialTimeHour = Integer.valueOf(sundayInitialTimeArray[0]).intValue();
initialTimeMinutes = Integer.valueOf(sundayInitialTimeArray[1]).intValue();
terminalTimeHour = Integer.valueOf(sundayTerminalTimeArray[0]).intValue();
terminalTimeMinutes = Integer.valueOf(sundayTerminalTimeArray[1]).intValue();
}


//Initial CITI Operating Time based on values getting from Rule
Calendar initialTimeCalendar = Calendar.getInstance(timeZone);
initialTimeCalendar.set(Calendar.HOUR_OF_DAY, initialTimeHour);
initialTimeCalendar.set(Calendar.MINUTE, initialTimeMinutes);
Calendar terminalTimeCalendar = Calendar.getInstance(timeZone);
terminalTimeCalendar.set(Calendar.HOUR_OF_DAY, terminalTimeHour);
terminalTimeCalendar.set(Calendar.MINUTE, terminalTimeMinutes);
timeIntervalBean.setCurrentCalendar(currentCalendar);
timeIntervalBean.setInitialTimeCalendar(initialTimeCalendar);
timeIntervalBean.setTerminalTimeCalendar(terminalTimeCalendar);


Calendar initialNextDay = Calendar.getInstance(timeZone);
initialNextDay.add(Calendar.DAY_OF_WEEK, 1);
Calendar terminalNextDay = Calendar.getInstance(timeZone);
terminalNextDay.add(Calendar.DAY_OF_WEEK, 1);
int initialTimeHourWeekEnd = Integer.valueOf(initialTimeArray[0]).intValue();
int initialTimeMinutesWeekEnd = Integer.valueOf(initialTimeArray[1]).intValue();
int terminalTimeHourNextday = Integer.valueOf(terminalTimeArray[0]).intValue();
int terminalTimeMinutesNextday = Integer.valueOf(terminalTimeArray[1]).intValue();
if(String.valueOf(initialNextDay.get(Calendar.DAY_OF_WEEK)).equals("6")){
// if(initialNextDay.get(Calendar.DAY_OF_WEEK) ==Integer.parseInt(noServiceDateArray[0]) || initialNextDay.get(Calendar.DAY_OF_WEEK) == Integer.parseInt(noServiceDateArray[1])){
//timeIntervalBean.setIsWeekendNextday(Boolean.TRUE);
initialTimeHourWeekEnd = Integer.valueOf(saturdayInitialTimeArray[0]).intValue();
initialTimeMinutesWeekEnd = Integer.valueOf(saturdayInitialTimeArray[1]).intValue();
terminalTimeHourNextday = Integer.valueOf(saturdayTerminalTimeArray[0]).intValue();
terminalTimeMinutesNextday = Integer.valueOf(saturdayTerminalTimeArray[1]).intValue();
}

if(String.valueOf(initialNextDay.get(Calendar.DAY_OF_WEEK)).equals("7")){
// if(initialNextDay.get(Calendar.DAY_OF_WEEK) ==Integer.parseInt(noServiceDateArray[0]) || initialNextDay.get(Calendar.DAY_OF_WEEK) == Integer.parseInt(noServiceDateArray[1])){
//timeIntervalBean.setIsWeekendNextday(Boolean.TRUE);
initialTimeHourWeekEnd = Integer.valueOf(sundayInitialTimeArray[0]).intValue();
initialTimeMinutesWeekEnd = Integer.valueOf(sundayInitialTimeArray[1]).intValue();
terminalTimeHourNextday = Integer.valueOf(sundayTerminalTimeArray[0]).intValue();
terminalTimeMinutesNextday = Integer.valueOf(sundayTerminalTimeArray[1]).intValue();
}

initialNextDay.set(Calendar.HOUR_OF_DAY, initialTimeHourWeekEnd);
initialNextDay.set(Calendar.MINUTE, initialTimeMinutesWeekEnd);
terminalNextDay.set(Calendar.HOUR_OF_DAY, terminalTimeHourNextday);
terminalNextDay.set(Calendar.MINUTE, terminalTimeMinutesNextday);
timeIntervalBean.setInitialTimeCalendarNextday(initialNextDay);
timeIntervalBean.setTerminalTimeCalendarNextday(terminalNextDay);

//Initial the last EndTime round 24 hours based on current Time.
Calendar endTimeCalendar = Calendar.getInstance(timeZone);

// endTimeCalendar.setTime(date);


endTimeCalendar.add(Calendar.DAY_OF_MONTH, 1);
System.out.println(endTimeCalendar.getTime()+"endTimeCalendar");
if(endTimeCalendar.after(terminalNextDay)){
endTimeCalendar = terminalNextDay;
} else if(endTimeCalendar.before(initialNextDay)){
endTimeCalendar = initialNextDay;
}
timeIntervalBean.setEndTimeCalendar(endTimeCalendar);


generateCallBackTimeList(timeIntervalBean);
List startTimeList =timeIntervalBean.getStartTimeList();
List endTimeList =timeIntervalBean.getEndTimeList();
for(int i=0;i<startTimeList.size();i++){
System.out.println(startTimeList.get(i)+"-----------"+endTimeList.get(i));
}
ctcBean.setStartTimeList(timeIntervalBean.getStartTimeList());
ctcBean.setEndTimeList(timeIntervalBean.getEndTimeList());
}

private static void generateCallBackTimeList(TimeIntervalBean timeIntervalBean){

int roundInterval = timeIntervalBean.getRoundInterval();
int firstTimeInterval = timeIntervalBean.getFirstTimeInterval();
int subTimeInterval = timeIntervalBean.getSubTimeInterval();
//Non-operating TimeMillis is used for calculating SubTimeInterval options recurring times
int invalidTimeMillis = (int)(timeIntervalBean.getInitialTimeCalendarNextday().getTimeInMillis() - timeIntervalBean.getTerminalTimeCalendar().getTimeInMillis());

Calendar currentCalendar = timeIntervalBean.getCurrentCalendar();

if(currentCalendar.before(timeIntervalBean.getInitialTimeCalendar())){
currentCalendar = timeIntervalBean.getInitialTimeCalendar();
}

//Generate StartTime of CallBackTimeList based on RoundInterval value from Rule
if(roundInterval != 0){
int tempInterval = currentCalendar.get(timeIntervalBean.getField()) + roundInterval;
currentCalendar.set(Calendar.MINUTE, roundInterval*((int)(tempInterval/roundInterval) ) );
}

//Generate First TimeInterval option
timeIntervalBean.setCurrentCalendar(currentCalendar);

generateList(timeIntervalBean, firstTimeInterval, 1);

//Generate Sub TimeInterval options
//the recurringTime is calculated via LastEndTimeRound24Hours - currentRecurringTime - Non-operatingTime
Calendar endTimeCalendar = timeIntervalBean.getEndTimeCalendar();

long totalTimeInMillis = endTimeCalendar.getTimeInMillis() - currentCalendar.getTimeInMillis() - invalidTimeMillis;
int subTimeIntervalRecuringTimes = (int)totalTimeInMillis / (subTimeInterval*60*1000) ;

generateList(timeIntervalBean, subTimeInterval, subTimeIntervalRecuringTimes);
}
/**
*
* @param timeIntervalBean
* @param interval
* @param recurringTimes
*/
private static void generateList(TimeIntervalBean timeIntervalBean, int interval, int recurringTimes){
List startTimeList = timeIntervalBean.getStartTimeList();
List endTimeList = timeIntervalBean.getEndTimeList();
//Calendar initialTimeCalendar = timeIntervalBean.getInitialTimeCalendar();
Calendar currentCalendar = timeIntervalBean.getCurrentCalendar();
Calendar endTimeCalendar = timeIntervalBean.getEndTimeCalendar();
Calendar tempEndTimeCalendar = Calendar.getInstance(currentCalendar.getTimeZone());

Calendar terminalTimeCalendar = timeIntervalBean.getTerminalTimeCalendar();
for(int i=0; i<recurringTimes; i++){
/*
* If TemporaryCalendar after increasing interval based on currentCalendar is after CITI Operating EndTime,
* step to CITI Operating StartTime of second day
*/
tempEndTimeCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + interval*60*1000);

if(tempEndTimeCalendar.after(timeIntervalBean.getTerminalTimeCalendar())){
currentCalendar = timeIntervalBean.getInitialTimeCalendarNextday();
terminalTimeCalendar = timeIntervalBean.getTerminalTimeCalendarNextday();
}
/*
* If TemporaryCalendar after increasing interval based on currentCalendar is after the last EndTime round 24Hours based on currentTime,
* break recurring
*/
if(tempEndTimeCalendar.after(endTimeCalendar)){
System.err.println("tempEndTimeCalendar "+tempEndTimeCalendar.getTime());
System.err.println("111111111");
break;
}

//Generate StartTime & EndTime and add into List
startTimeList.add(currentCalendar.getTime());
currentCalendar.add(Calendar.MINUTE, interval);
endTimeList.add(currentCalendar.getTime());
}
timeIntervalBean.setStartTimeList(startTimeList);
timeIntervalBean.setEndTimeList(endTimeList);
timeIntervalBean.setTerminalTimeCalendar(terminalTimeCalendar);
timeIntervalBean.setCurrentCalendar(currentCalendar);
}


public static void main(String[] args) throws ParseException {
// Map map =new HashMap();
// map.put("1", "1V");
// map.put("2", "2V");
// map.put("3", "3V");
// StringBuffer test=new StringBuffer();
// String key="";
// String value="";
// Set set = map.keySet();set.size();
// Iterator it =set.iterator();
// while(it.hasNext()){
// key = (String)it.next();
// value = (String)map.get(key);
// test.append(key).append("=").append(value).append("=");
// }
//
// String rs = test.substring(0, test.lastIndexOf("="));
// System.out.println(test);
// test();
generateCallBackTimeList();
// Calendar cal=Calendar.getInstance();
// cal.setTime(new Date());
// System.out.println("hh:"+cal.get(Calendar.HOUR_OF_DAY)+" mm:"+cal.get(Calendar.MINUTE));

}

}
获取当天日期 获取本周一日期 获取本周日的日期 获取上周一日期:" + tt.getPreviousWeekday("yyyy-MM-dd")); 获取上周日日期:" + tt.getPreviousWeekSunday("yyyy-MM-dd")); 获取上周一日期:" + tt.getWeekday(-1, "yyyy-MM-dd")); 获取上周日日期:" + tt.getWeekSunday(-1, "yyyy-MM-dd")); 获取下周一日期:" + tt.getNextMonday("yyyy-MM-dd")); 获取下周日日期:" + tt.getNextSunday("yyyy-MM-dd")); 获取本月第一天日期:" + tt.getFirstDayOfMonth()); 获取本月最后一天日期:" + tt.getDefaultDay()); 获取上月第一天日期:" + tt.getPreviousMonthFirst("yyyy-MM-dd")); 获取上月最后一天的日期:" + tt.getPreviousMonthEnd("yyyy-MM-dd")); 获取某月第一天日期:" + tt.getMonthFirst(0, "yyyy-MM-dd")); 获取某月最后一天的日期:" + tt.getMonthEnd(0, "yyyy-MM-dd")); 获取下月第一天日期:" + tt.getNextMonthFirst("yyyy-MM-dd")); 获取下月最后一天日期:" + tt.getNextMonthEnd("yyyy-MM-dd")); 获取本年的第一天日期:" + tt.getCurrentYearFirst()); 获取本年最后一天日期:" + tt.getCurrentYearEnd()); 获取去年的第一天日期:" + tt.getPreviousYearFirst()); 获取去年的最后一天日期:" + tt.getPreviousYearEnd()); 获取明年第一天日期:" + tt.getNextYearFirst()); 获取明年最后一天日期:" + tt.getNextYearEnd()); 获取本季度第一天:" + tt.getThisSeasonFirstTime(11)); 获取本季度最后一天:" + tt.getThisSeasonFinallyTime(11)); 获取两个日期之间间隔天数 获取当前月的第几周:" + tt.getWeekOfMonth()); 获取当前年份:" + tt.getYear()); 获取当前月份:" + tt.getMonth()); 获取今天在本年的第几天:" + tt.getDayOfYear()); 获得今天在本月的第几天(获得当前日):" + tt.getDayOfMonth()); 获得今天在本周的第几天:" + tt.getDayOfWeek()); 字符串转时间 获得一个日期所在周的星期几的日期
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值