Java Utililty Methods Calendar Calculate

List of utility methods to do Calendar Calculate

Description

The list of methods to do Calendar Calculate are organized into topic(s).

Method

voidroundBack(Calendar start)
Rounds a date backwards if it found to be before th start of a work day.
if (!(isInWorkDay(start) && isInWorkTime(start))) {
    if (isBeforeWorkTime(start) || !isInWorkDay(start)) {
        start.add(Calendar.DATE, -1);
    if (start.get(Calendar.DAY_OF_WEEK) == 1) {
        start.add(Calendar.DATE, -2);
    if (start.get(Calendar.DAY_OF_WEEK) == 7) {
...
GregorianCalendarroundCalToNextQuarterHour(GregorianCalendar cal)
Returns a calendar that has been rounded to the next quarter hour and zeros out the seconds and milliseconds.
int minutes = cal.get(Calendar.MINUTE);
if (minutes > 45) {
    cal.set(Calendar.MINUTE, 0);
    cal.add(Calendar.HOUR, 1);
} else if (minutes > 30) {
    cal.set(Calendar.MINUTE, 45);
} else if (minutes > 15) {
    cal.set(Calendar.MINUTE, 30);
...
Datetransform(Calendar cal)
transform
return cal.getTime();
Calendartruncate(Calendar ca)
Truncate to begin of day: 0 hour 0 minute 0 second 0 millisecond
truncateHour(ca);
ca.set(Calendar.HOUR_OF_DAY, 0);
return ca;
voidtruncateHour(Calendar ca)
truncate Hour
ca.set(Calendar.MILLISECOND, 0);
ca.set(Calendar.SECOND, 0);
ca.set(Calendar.MINUTE, 0);