dailycalendar.java
来自「Quartz 是个开源的作业调度框架」· Java 代码 · 共 803 行 · 第 1/3 页
JAVA
803 行
buffer.append(getBaseCalendar().toString());
} else {
buffer.append("null");
}
buffer.append("], time range: '");
buffer.append(numberFormatter.format(rangeStartingHourOfDay));
buffer.append(":");
buffer.append(numberFormatter.format(rangeStartingMinute));
buffer.append(":");
buffer.append(numberFormatter.format(rangeStartingSecond));
buffer.append(":");
numberFormatter.setMinimumIntegerDigits(3);
buffer.append(numberFormatter.format(rangeStartingMillis));
numberFormatter.setMinimumIntegerDigits(2);
buffer.append(" - ");
buffer.append(numberFormatter.format(rangeEndingHourOfDay));
buffer.append(":");
buffer.append(numberFormatter.format(rangeEndingMinute));
buffer.append(":");
buffer.append(numberFormatter.format(rangeEndingSecond));
buffer.append(":");
numberFormatter.setMinimumIntegerDigits(3);
buffer.append(numberFormatter.format(rangeEndingMillis));
buffer.append("', inverted: " +
Boolean.toString(invertTimeRange) + "]");
return buffer.toString();
}
/**
* Sets the time range for the <CODE>DailyCalendar</CODE> to the times
* represented in the specified Strings.
*
* @param rangeStartingTimeString a String representing the start time of
* the time range
* @param rangeEndingTimeString a String representing the end time of the
* excluded time range
*/
private void setTimeRange(String rangeStartingTimeString,
String rangeEndingTimeString) {
String[] rangeStartingTime;
int rangeStartingHourOfDay;
int rangeStartingMinute;
int rangeStartingSecond;
int rangeStartingMillis;
String[] rangeEndingTime;
int rangeEndingHourOfDay;
int rangeEndingMinute;
int rangeEndingSecond;
int rangeEndingMillis;
rangeStartingTime = rangeStartingTimeString.split(colon);
if ((rangeStartingTime.length < 2) || (rangeStartingTime.length > 4)) {
throw new IllegalArgumentException("Invalid time string '" +
rangeStartingTimeString + "'");
}
rangeStartingHourOfDay = Integer.parseInt(rangeStartingTime[0]);
rangeStartingMinute = Integer.parseInt(rangeStartingTime[1]);
if (rangeStartingTime.length > 2) {
rangeStartingSecond = Integer.parseInt(rangeStartingTime[2]);
} else {
rangeStartingSecond = 0;
}
if (rangeStartingTime.length == 4) {
rangeStartingMillis = Integer.parseInt(rangeStartingTime[3]);
} else {
rangeStartingMillis = 0;
}
rangeEndingTime = rangeEndingTimeString.split(colon);
if ((rangeEndingTime.length < 2) || (rangeEndingTime.length > 4)) {
throw new IllegalArgumentException("Invalid time string '" +
rangeEndingTimeString + "'");
}
rangeEndingHourOfDay = Integer.parseInt(rangeEndingTime[0]);
rangeEndingMinute = Integer.parseInt(rangeEndingTime[1]);
if (rangeEndingTime.length > 2) {
rangeEndingSecond = Integer.parseInt(rangeEndingTime[2]);
} else {
rangeEndingSecond = 0;
}
if (rangeEndingTime.length == 4) {
rangeEndingMillis = Integer.parseInt(rangeEndingTime[3]);
} else {
rangeEndingMillis = 0;
}
setTimeRange(rangeStartingHourOfDay,
rangeStartingMinute,
rangeStartingSecond,
rangeStartingMillis,
rangeEndingHourOfDay,
rangeEndingMinute,
rangeEndingSecond,
rangeEndingMillis);
}
/**
* Sets the time range for the <CODE>DailyCalendar</CODE> to the times
* represented in the specified values.
*
* @param rangeStartingHourOfDay the hour of the start of the time range
* @param rangeStartingMinute the minute of the start of the time range
* @param rangeStartingSecond the second of the start of the time range
* @param rangeStartingMillis the millisecond of the start of the time
* range
* @param rangeEndingHourOfDay the hour of the end of the time range
* @param rangeEndingMinute the minute of the end of the time range
* @param rangeEndingSecond the second of the end of the time range
* @param rangeEndingMillis the millisecond of the start of the time
* range
*/
private void setTimeRange(int rangeStartingHourOfDay,
int rangeStartingMinute,
int rangeStartingSecond,
int rangeStartingMillis,
int rangeEndingHourOfDay,
int rangeEndingMinute,
int rangeEndingSecond,
int rangeEndingMillis) {
validate(rangeStartingHourOfDay,
rangeStartingMinute,
rangeStartingSecond,
rangeStartingMillis);
validate(rangeEndingHourOfDay,
rangeEndingMinute,
rangeEndingSecond,
rangeEndingMillis);
Calendar startCal = Calendar.getInstance();
startCal.set(Calendar.HOUR_OF_DAY, rangeStartingHourOfDay);
startCal.set(Calendar.MINUTE, rangeStartingMinute);
startCal.set(Calendar.SECOND, rangeStartingSecond);
startCal.set(Calendar.MILLISECOND, rangeStartingMillis);
Calendar endCal = Calendar.getInstance();
endCal.set(Calendar.HOUR_OF_DAY, rangeEndingHourOfDay);
endCal.set(Calendar.MINUTE, rangeEndingMinute);
endCal.set(Calendar.SECOND, rangeEndingSecond);
endCal.set(Calendar.MILLISECOND, rangeEndingMillis);
if (!startCal.before(endCal)) {
throw new IllegalArgumentException(invalidTimeRange +
rangeStartingHourOfDay + ":" +
rangeStartingMinute + ":" +
rangeStartingSecond + ":" +
rangeStartingMillis + separator +
rangeEndingHourOfDay + ":" +
rangeEndingMinute + ":" +
rangeEndingSecond + ":" +
rangeEndingMillis);
}
this.rangeStartingHourOfDay = rangeStartingHourOfDay;
this.rangeStartingMinute = rangeStartingMinute;
this.rangeStartingSecond = rangeStartingSecond;
this.rangeStartingMillis = rangeStartingMillis;
this.rangeEndingHourOfDay = rangeEndingHourOfDay;
this.rangeEndingMinute = rangeEndingMinute;
this.rangeEndingSecond = rangeEndingSecond;
this.rangeEndingMillis = rangeEndingMillis;
}
/**
* Sets the time range for the <CODE>DailyCalendar</CODE> to the times
* represented in the specified <CODE>java.util.Calendar</CODE>s.
*
* @param rangeStartingCalendar a Calendar containing the start time for
* the <CODE>DailyCalendar</CODE>
* @param rangeEndingCalendar a Calendar containing the end time for
* the <CODE>DailyCalendar</CODE>
*/
private void setTimeRange(Calendar rangeStartingCalendar,
Calendar rangeEndingCalendar) {
setTimeRange(
rangeStartingCalendar.get(Calendar.HOUR_OF_DAY),
rangeStartingCalendar.get(Calendar.MINUTE),
rangeStartingCalendar.get(Calendar.SECOND),
rangeStartingCalendar.get(Calendar.MILLISECOND),
rangeEndingCalendar.get(Calendar.HOUR_OF_DAY),
rangeEndingCalendar.get(Calendar.MINUTE),
rangeEndingCalendar.get(Calendar.SECOND),
rangeEndingCalendar.get(Calendar.MILLISECOND));
}
/**
* Sets the time range for the <CODE>DailyCalendar</CODE> to the times
* represented in the specified values.
*
* @param rangeStartingTime the starting time (in milliseconds) for the
* time range
* @param rangeEndingTime the ending time (in milliseconds) for the time
* range
*/
private void setTimeRange(long rangeStartingTime,
long rangeEndingTime) {
Calendar startCal = Calendar.getInstance();
Calendar endCal = Calendar.getInstance();
startCal.setTimeInMillis(rangeStartingTime);
endCal.setTimeInMillis(rangeEndingTime);
setTimeRange(startCal, endCal);
}
/**
* Returns the start of the given day in milliseconds
*
* @param timeInMillis a time containing the desired date for the
* start-of-day time.
* @return the start of the given day in milliseconds
*/
private long getStartOfDayInMillis(long timeInMillis) {
Calendar startOfDay = Calendar.getInstance();
startOfDay.setTimeInMillis(timeInMillis);
startOfDay.set(Calendar.HOUR_OF_DAY, 0);
startOfDay.set(Calendar.MINUTE, 0);
startOfDay.set(Calendar.SECOND, 0);
startOfDay.set(Calendar.MILLISECOND, 0);
return startOfDay.getTimeInMillis();
}
/**
* Returns the end of the given day in milliseconds
*
* @param timeInMillis a time containing the desired date for the
* end-of-day time.
* @return the end of the given day in milliseconds
*/
private long getEndOfDayInMillis(long timeInMillis) {
Calendar endOfDay = Calendar.getInstance();
endOfDay.setTimeInMillis(timeInMillis);
endOfDay.set(Calendar.HOUR_OF_DAY, 23);
endOfDay.set(Calendar.MINUTE, 59);
endOfDay.set(Calendar.SECOND, 59);
endOfDay.set(Calendar.MILLISECOND, 999);
return endOfDay.getTimeInMillis();
}
/**
* Checks the specified values for validity as a set of time values.
*
* @param hourOfDay the hour of the time to check (in military (24-hour)
* time)
* @param minute the minute of the time to check
* @param second the second of the time to check
* @param millis the millisecond of the time to check
*/
private void validate(int hourOfDay, int minute, int second, int millis) {
if (hourOfDay < 0 || hourOfDay > 23) {
throw new IllegalArgumentException(invalidHourOfDay + hourOfDay);
}
if (minute < 0 || minute > 59) {
throw new IllegalArgumentException(invalidMinute + minute);
}
if (second < 0 || second > 59) {
throw new IllegalArgumentException(invalidSecond + second);
}
if (millis < 0 || millis > 999) {
throw new IllegalArgumentException(invalidMillis + millis);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?