Example usage for java.util Calendar before

List of usage examples for java.util Calendar before

Introduction

In this page you can find the example usage for java.util Calendar before.

Prototype

public boolean before(Object when) 

Source Link

Document

Returns whether this Calendar represents a time before the time represented by the specified Object.

Usage

From source file:com.glaf.core.util.DateUtils.java

/**
 * ?time2??time1?/* www.j  a v a2s .  c om*/
 * 
 * @param time1
 * @param time2
 * @return
 */
public static boolean beforeTime(Date time1, Date time2) {
    Calendar calendar1 = Calendar.getInstance();
    calendar1.setTime(time1);

    Calendar calendar2 = Calendar.getInstance();
    calendar2.setTime(time2);

    return calendar1.before(calendar2);
}

From source file:org.openestate.io.immobiliare_it.ImmobiliareItUtils.java

public static boolean isValidDateUpdatedType(Calendar value) {
    final Calendar min = DatatypeConverter.parseDateTime("2000-12-31T00:00:00");
    return value != null && !value.before(min);
}

From source file:com.maydesk.base.util.PDUtil.java

public static boolean isBefore(Date date1, Date date2) {
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(date1);/*from  w  w  w.  ja  v a 2  s .c o  m*/
    cal1.set(Calendar.HOUR, 0);
    cal1.set(Calendar.MINUTE, 0);
    cal1.set(Calendar.SECOND, 0);
    Calendar cal2 = Calendar.getInstance();
    cal1.setTime(date1);
    cal1.set(Calendar.HOUR, 0);
    cal1.set(Calendar.MINUTE, 0);
    cal1.set(Calendar.SECOND, 0);
    return cal1.before(cal2);
}

From source file:org.kuali.kfs.sys.batch.Job.java

/**
 * Checks if the current jobRunDate is within the cutoff window for the given run date from the RUN_DATE parameter.
 * The window is defined as midnight of the date specified in the parameter to the RUN_DATE_CUTOFF_TIME of the next day.
 * //from  w  w  w .  j  a va 2  s  .  c  o  m
 * @param jobRunDate the time the job is attempting to start
 * @param runDateToCheck the current member of the appropriate RUN_DATE to check
 * @param dateTimeService an instance of the DateTimeService
 * @return true if jobRunDate is within the current runDateToCheck window, false otherwise
 */
protected static boolean withinCutoffWindowForDate(Date jobRunDate, Date runDateToCheck,
        DateTimeService dateTimeService, String[] cutOffWindow) {
    final Calendar jobRunCalendar = dateTimeService.getCalendar(jobRunDate);
    final Calendar beginWindow = getCutoffWindowBeginning(runDateToCheck, dateTimeService);
    final Calendar endWindow = getCutoffWindowEnding(runDateToCheck, dateTimeService, cutOffWindow);
    return jobRunCalendar.after(beginWindow) && jobRunCalendar.before(endWindow);
}

From source file:Dates.java

/** 
 * Returns number of days between startDate and endDate<p> 
 *  //from ww w.  j av  a 2 s  .  c om
 * @param java.util.Date startDate
 * @param java.util.Date endDate
 * @param boolean includeStartDate<p>
 *  
 */
public static int daysInterval(Date startDate, Date endDate, boolean includeStartDate) {

    startDate = Dates.removeTime(startDate);
    Calendar start = Calendar.getInstance();
    start.setTime(startDate);

    endDate = Dates.removeTime(endDate);
    Calendar end = Calendar.getInstance();
    end.setTime(endDate);

    if (includeStartDate) {
        start.add(Calendar.DATE, -1);
    }

    int days = 0;
    while (start.before(end)) {
        days++;
        start.add(Calendar.DATE, 1);
    }
    return days;
}

From source file:com.vmware.identity.rest.core.server.util.VerificationUtil.java

/**
 * Verify the issued-at and expires-at dates in an access token
 *
 * @param token the token to verify//from  w  ww  .  ja v a2 s.com
 * @param skew the amount of skew to allow in milliseconds
 * @param sm a string manager to get the exception messages from
 *
 * @throws InvalidTokenException if the token is at an invalid date
 */
public static void verifyTimestamps(AccessToken token, long skew, StringManager sm)
        throws InvalidTokenException {
    Calendar now = Calendar.getInstance();
    Calendar issuedAt = Calendar.getInstance();
    Calendar expiresAt = Calendar.getInstance();

    if (token.getIssueTime() != null) {
        issuedAt.setTimeInMillis(token.getIssueTime().getTime() - skew);
    }

    if (token.getExpirationTime() != null) {
        expiresAt.setTimeInMillis(token.getExpirationTime().getTime() + skew);
    }

    if (token.getIssueTime() == null || issuedAt.after(now)) {
        throw new InvalidTokenException(sm.getString("auth.ite.bad.issue", issuedAt.getTime(), now.getTime()));
    }

    if (token.getExpirationTime() == null || expiresAt.before(now)) {
        throw new InvalidTokenException(
                sm.getString("auth.ite.bad.expiry", expiresAt.getTime(), now.getTime()));
    }
}

From source file:com.example.reminder.alarm.AlarmUtils.java

private static Calendar getAlarmTime(Alarm alarm) {

    Calendar alarmCalendar = Calendar.getInstance();
    int addDays = alarm.daysOfWeek.calculateDaysToNextAlarm(alarmCalendar);
    Log.d(TAG, "days to add: " + addDays);
    if (addDays > 0) { //should always be
        alarmCalendar.add(Calendar.DATE, addDays);
    }/* w w  w  . jav a  2s  . co  m*/

    alarmCalendar.set(Calendar.HOUR_OF_DAY, alarm.hour);
    alarmCalendar.set(Calendar.MINUTE, alarm.minutes);
    alarmCalendar.set(Calendar.SECOND, 0);
    alarmCalendar.set(Calendar.MILLISECOND, 0);

    //don't schedule alarms in the past that were supposed to fire today
    while (alarmCalendar.before(Calendar.getInstance())) {
        if (!alarm.daysOfWeek.isRepeating()) {
            break;
        } else {
            alarmCalendar.add(Calendar.DATE, 1);
            addDays = alarm.daysOfWeek.calculateDaysToNextAlarm(alarmCalendar);
            if (addDays > 0) {
                alarmCalendar.add(Calendar.DATE, addDays);
            }
        }
    }

    return alarmCalendar;
}

From source file:com.wkb.core.util.IdcardUtils.java

/**
 * ???,/*from w  w  w . ja  va2  s  .c  o  m*/
 * 
 * @param idCard
 *            ?
 * @return 
 */
public static int getAccurateAgeByIdCard(String idCard) {
    int iAge = getAgeByIdCard(idCard);

    String birthDay = getBirthByIdCard(idCard);
    Date birthDate = null;
    try {
        birthDate = sdf.parse(birthDay);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Calendar birthCal = Calendar.getInstance();
    birthCal.setTime(birthDate);
    birthCal.set(Calendar.HOUR_OF_DAY, 0);
    birthCal.set(Calendar.MINUTE, 0);
    birthCal.set(Calendar.SECOND, 0);
    Calendar curCal = Calendar.getInstance();
    if (curCal.before(birthCal))
        iAge = iAge - 1;
    return iAge;
}

From source file:com.kunze.androidlocaltodo.TaskActivityFragment.java

private static void SetFriendlyDueDateText(TextView dueDateView, Calendar dueDate) {
    SimpleDateFormat dateFormatDisplay = new SimpleDateFormat("MM-dd-yyyy", Locale.US);
    Calendar now = Calendar.getInstance();
    int nowDay = TaskDatabase.ConvertDateToInt(now);
    int dueDay = TaskDatabase.ConvertDateToInt(dueDate);
    int dayDiff = nowDay - dueDay;
    if (dayDiff == 0) {
        dueDateView.setText("Today");
        dueDateView.setTextColor(Color.RED);
    } else if (dueDate.before(now)) {
        dueDateView.setText("+ " + dayDiff + " days!");
        dueDateView.setTextColor(Color.RED);
    } else if (dayDiff > -7) {
        dueDateView.setText(dueDate.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.US));
        dueDateView.setTextColor(Color.BLACK);
    } else if (dayDiff > -14) {
        dueDateView.setText("Next " + dueDate.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.US));
        dueDateView.setTextColor(Color.BLACK);
    } else {/*from www  .  j a v a 2 s.co  m*/
        dueDateView.setText(dateFormatDisplay.format(dueDate.getTime()));
        dueDateView.setTextColor(Color.BLACK);
    }
}

From source file:net.kamhon.ieagle.util.DateUtil.java

/**
 * Calculate Age base on date of birth until onDate.
 * // w ww  .j  a  v  a 2s .  com
 * @param dob
 * @return
 */
public static int countAge(Date dob, Date onDate) {

    // Create a calendar object with today's date
    Calendar today = Calendar.getInstance();
    today.setTime(DateUtil.truncateTime(onDate));
    Calendar calendarDob = Calendar.getInstance();
    calendarDob.setTime(DateUtil.truncateTime(dob));

    // Get age based on year
    int age = today.get(Calendar.YEAR) - calendarDob.get(Calendar.YEAR);

    // Add the tentative age to the date of birth to get this year's
    // birthday
    calendarDob.add(Calendar.YEAR, age);

    // If this year's birthday has not happened yet, subtract one from age
    if (today.before(calendarDob)) {
        age--;
    }
    return age;
}