Java Code Examples for org.apache.commons.lang3.time.DateUtils#toCalendar()

The following examples show how to use org.apache.commons.lang3.time.DateUtils#toCalendar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseWorkTime.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
protected Calendar forwardStartOfRegion(Calendar c) {
	Calendar cx = DateUtils.toCalendar(c.getTime());
	long cm = DateUtils.getFragmentInMilliseconds(cx, Calendar.DATE);
	switch (inRegion(cx)) {
	case 1:
		cx.add(Calendar.MILLISECOND, (int) (t2 - cm));
		break;
	case 3:
		cx.add(Calendar.MILLISECOND, (int) (t4 - cm));
		break;
	case 5:
		cx.add(Calendar.MILLISECOND, (int) ((t6 - cm) + t2t1));
		break;
	}
	return cx;
}
 
Example 2
Source File: BaseWorkTime.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
protected Calendar backwardEndOfRegion(Calendar c) {
	Calendar cx = DateUtils.toCalendar(c.getTime());
	long cm = DateUtils.getFragmentInMilliseconds(cx, Calendar.DATE);
	switch (inRegion(cx)) {
	case 1:
		cx.add(Calendar.MILLISECOND, -(int) ((cm - t1) + t6t5));
		break;
	case 3:
		cx.add(Calendar.MILLISECOND, -(int) (cm - t3));
		break;
	case 5:
		cx.add(Calendar.MILLISECOND, -(int) (cm - t5));
		break;
	}
	return cx;
}
 
Example 3
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public static Integer season(Date date) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	switch (cal.get(Calendar.MONTH)) {
	case Calendar.JANUARY:
	case Calendar.FEBRUARY:
	case Calendar.MARCH:
		return 1;
	case Calendar.APRIL:
	case Calendar.MAY:
	case Calendar.JUNE:
		return 2;
	case Calendar.JULY:
	case Calendar.AUGUST:
	case Calendar.SEPTEMBER:
		return 3;
	case Calendar.OCTOBER:
	case Calendar.NOVEMBER:
	case Calendar.DECEMBER:
	default:
		return 4;
	}
}
 
Example 4
Source File: BattleAggDialog.java    From logbook with MIT License 6 votes vote down vote up
public BattleResult(String line) {
    try {
        String[] cols = line.split(",", -1);
        // 日付書式
        SimpleDateFormat format = new SimpleDateFormat(AppConstants.DATE_FORMAT);
        // 日付
        this.date = DateUtils.toCalendar(format.parse(cols[0]));
        this.date.setTimeZone(AppConstants.TIME_ZONE_MISSION);
        this.date.setFirstDayOfWeek(Calendar.MONDAY);
        // 海域
        this.area = cols[1];
        // ランク
        this.rank = cols[4];
        // 出撃
        this.isStart = StringUtils.indexOf(cols[3], "出撃") > -1;
        // ボス
        this.isBoss = StringUtils.indexOf(cols[3], "ボス") > -1;
    } catch (ParseException e) {
    }
}
 
Example 5
Source File: BaseWorkTime.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Calendar forwardMilliSeconds(Calendar c, long milliSeconds) {
	Calendar f = DateUtils.toCalendar(c.getTime());
	long l = milliSeconds % this.workMilliSecondsOfDay();
	long fm = DateUtils.getFragmentInMilliseconds(f, Calendar.DATE);
	switch (inRegion(f)) {
	case 2:
		if (l - t5t4 - (t3 - fm) >= 0) {
			f.add(Calendar.MILLISECOND, (int) (l + t4t3 + t6t5 + t2t1));
		} else if (l - (t3 - fm) >= 0) {
			f.add(Calendar.MILLISECOND, (int) (l + t4t3));
		} else {
			f.add(Calendar.MILLISECOND, (int) (l));
		}
		break;
	case 4:
		if ((l - (t5 - fm) - t3t2) >= 0) {
			f.add(Calendar.MILLISECOND, (int) (l + t6t5 + t2t1 + t4t3));
		} else if ((l - (t5 - fm)) >= 0) {
			f.add(Calendar.MILLISECOND, (int) (l + t6t5 + t2t1));
		} else {
			f.add(Calendar.MILLISECOND, (int) (l));
		}
		break;
	}
	while (this.isHoliday(f)) {
		f.add(Calendar.DATE, 1);
	}
	long day = (long) Math.floor(milliSeconds / this.workMilliSecondsOfDay());
	while (day > 0) {
		f.add(Calendar.DATE, 1);
		if (!this.isHoliday(f)) {
			day--;
		}
	}
	return f;
}
 
Example 6
Source File: DingdingAttendanceFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private Date endOneDate(Date date) throws Exception {
    Calendar cal = DateUtils.toCalendar(date);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}
 
Example 7
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Date ceilDate(Date date, Integer adjust) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	if ((null != adjust) && (adjust != 0)) {
		cal.add(Calendar.DATE, adjust);
	}
	return DateUtils.ceiling(cal, Calendar.DATE).getTime();
}
 
Example 8
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Date floorDate(Date date, Integer adjust) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	if ((null != adjust) && (adjust != 0)) {
		cal.add(Calendar.DATE, adjust);
	}
	cal.set(Calendar.HOUR_OF_DAY, 0);
	cal.set(Calendar.MINUTE, 0);
	cal.set(Calendar.SECOND, 0);
	cal.set(Calendar.MILLISECOND, 0);
	return cal.getTime();
}
 
Example 9
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Date ceilMonth(Date date, Integer adjust) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	if ((null != adjust) && (adjust != 0)) {
		cal.add(Calendar.MONTH, adjust);
	}
	return DateUtils.ceiling(cal, Calendar.MONTH).getTime();
}
 
Example 10
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Date floorMonth(Date date, Integer adjust) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	if ((null != adjust) && (adjust != 0)) {
		cal.add(Calendar.MONTH, adjust);
	}
	cal.set(Calendar.DAY_OF_MONTH, 1);
	cal.set(Calendar.HOUR_OF_DAY, 0);
	cal.set(Calendar.MINUTE, 0);
	cal.set(Calendar.SECOND, 0);
	cal.set(Calendar.MILLISECOND, 0);
	return cal.getTime();
}
 
Example 11
Source File: ToStringParameterizedTest.java    From feilong-core with Apache License 2.0 5 votes vote down vote up
/**
 * Data.
 *
 * @return the iterable
 */
@Parameters(name = "index:{index}: ConvertUtil.toString({0})={1}")
public static Iterable<Object[]> data(){
    Object[][] objects = new Object[][] { //
                                          { null, null },

                                          { 1L, "1" },
                                          { toLong(8L), "8" },

                                          { new Double(1.0), "1.00" },
                                          { new Float(1.0), "1.00" },
                                          { toBigDecimal(1.0), "1.00" },
                                          {
                                            toDate("2019-06-28 12:00:00.666", COMMON_DATE_AND_TIME_WITH_MILLISECOND),
                                            "2019-06-28 12:00:00" },
                                          {
                                            DateUtils.toCalendar(
                                                            toDate("2019-06-28 12:00:00.666", COMMON_DATE_AND_TIME_WITH_MILLISECOND)),
                                            "2019-06-28 12:00:00" },

                                          { toList("张飞", "关羽", "", "赵云"), "张飞,关羽,,赵云" },
                                          { toArray("张飞", "关羽", "", "赵云"), "张飞,关羽,,赵云" },
                                          { toArray(null, "关羽", "", "赵云"), ",关羽,,赵云" },
            //
    };
    return toList(objects);
}
 
Example 12
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Date ceilWeekOfYear(String year, Integer weekOfYear, Integer adjust) throws Exception {
	Date date = parse(year, format_yyyy);
	Calendar cal = DateUtils.toCalendar(date);
	cal.setFirstDayOfWeek(Calendar.MONDAY);
	cal.set(Calendar.WEEK_OF_YEAR, weekOfYear);
	return ceilWeekOfYear(cal.getTime(), adjust);
}
 
Example 13
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Date floorWeekOfYear(Date date, Integer adjust) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	cal.setFirstDayOfWeek(Calendar.MONDAY);
	cal.add(Calendar.WEEK_OF_YEAR, adjust);
	cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
	cal.set(Calendar.HOUR_OF_DAY, 0);
	cal.set(Calendar.MINUTE, 0);
	cal.set(Calendar.SECOND, 0);
	cal.set(Calendar.MILLISECOND, 0);
	return cal.getTime();
}
 
Example 14
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Date ceilYear(Date date, Integer adjust) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	if ((null != adjust) && (adjust != 0)) {
		cal.add(Calendar.YEAR, adjust);
	}
	return DateUtils.ceiling(cal, Calendar.YEAR).getTime();

}
 
Example 15
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Date floorYear(Date date, Integer adjust) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	if ((null != adjust) && (adjust != 0)) {
		cal.add(Calendar.YEAR, adjust);
	}
	cal.set(Calendar.MONTH, Calendar.JANUARY);
	cal.set(Calendar.DAY_OF_MONTH, 1);
	cal.set(Calendar.HOUR_OF_DAY, 0);
	cal.set(Calendar.MINUTE, 0);
	cal.set(Calendar.SECOND, 0);
	cal.set(Calendar.MILLISECOND, 0);
	return cal.getTime();
}
 
Example 16
Source File: BaseWorkTime.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Calendar backwardEndOfWorkday(Calendar c) {
	Calendar cx = DateUtils.toCalendar(c.getTime());
	if (this.isHoliday(cx)) {
		while (this.isHoliday(cx)) {
			cx.add(Calendar.DATE, -1);
		}
		cx.add(Calendar.MILLISECOND, (int) (t5 - DateUtils.getFragmentInMilliseconds(cx, Calendar.DATE)));
	}
	return cx;
}
 
Example 17
Source File: BaseWorkTime.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Calendar forwardStartOfWorkday(Calendar c) {
	Calendar cx = DateUtils.toCalendar(c.getTime());
	if (this.isHoliday(cx)) {
		while (this.isHoliday(cx)) {
			cx.add(Calendar.DATE, 1);
		}
		cx.add(Calendar.MILLISECOND, (int) (t2 - DateUtils.getFragmentInMilliseconds(cx, Calendar.DATE)));
	}
	return cx;
}
 
Example 18
Source File: BaseWorkTime.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
protected long workDaysBetween(Calendar s, Calendar e) {
	long i = 0;
	if (s.before(e)) {
		Calendar sx = DateUtils.toCalendar(s.getTime());
		Calendar ex = DateUtils.toCalendar(e.getTime());
		while (!DateUtils.isSameDay(sx, ex)) {
			sx.add(Calendar.DATE, 1);
			if (!this.isHoliday(sx)) {
				i++;
			}
		}
	}
	return i;
}
 
Example 19
Source File: DateTools.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Integer week(Date date) throws Exception {
	Calendar cal = DateUtils.toCalendar(date);
	cal.setFirstDayOfWeek(Calendar.MONDAY);
	return cal.get(Calendar.WEEK_OF_YEAR);
}
 
Example 20
Source File: DateUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 将 {@link Date} 转成 {@link Calendar},调用 {@link GregorianCalendar}.
 * 
 * <p>
 * {@link Calendar#getInstance()}方法,返回用默认的地区和时区的当前日期和当前时间所初始化的GregorianCalendar(标准日历),<br>
 * 最终会调用 java.util.Calendar.createCalendar(TimeZone, Locale) 方法,<br>
 * 该方法会判断Locale(日本和泰国),其他国家最终会调用 {@link GregorianCalendar#GregorianCalendar(java.util.TimeZone, java.util.Locale)} 方法
 * </p>
 * 
 * <h3>{@link GregorianCalendar}</h3>
 * 
 * <blockquote>
 * <p>
 * 标准阳历格列高利历/公历,现在的公历是根据罗马人的"儒略历"改编而
 * </p>
 * </blockquote>
 *
 * @param date
 *            任意时间
 * @return 如果date 是null,抛出 {@link NullPointerException}
 * @see Calendar#getInstance()
 * @see GregorianCalendar
 * @see Calendar#setTime(Date)
 * @see Calendar#setTimeInMillis(long)
 * @see org.apache.commons.lang3.time.DateUtils#toCalendar(Date)
 * @since 1.8.3 remove public
 */
static Calendar toCalendar(Date date){
    Validate.notNull(date, "date can't be null!");
    return DateUtils.toCalendar(date);
}