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.sitexa.android.community.utils.DateUtil.java

/**
 * ??// w w w .  j ava2  s.c o m
 */
public static int getAgeByBirthday(Date birthday) {
    Calendar cal = Calendar.getInstance();

    if (cal.before(birthday)) {
        throw new IllegalArgumentException("The birthDay is before Now.It's unbelievable!");
    }

    int yearNow = cal.get(Calendar.YEAR);
    int monthNow = cal.get(Calendar.MONTH) + 1;
    int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);

    cal.setTime(birthday);
    int yearBirth = cal.get(Calendar.YEAR);
    int monthBirth = cal.get(Calendar.MONTH) + 1;
    int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);

    int age = yearNow - yearBirth;

    if (monthNow <= monthBirth) {
        if (monthNow == monthBirth) {
            // monthNow==monthBirth
            if (dayOfMonthNow < dayOfMonthBirth) {
                age--;
            }
        } else {
            // monthNow>monthBirth
            age--;
        }
    }
    return age;
}

From source file:Main.java

private static void populateDayRanges(Date start, Date end) {
    Calendar startCal = Calendar.getInstance();
    startCal.setTime(start);/*from w  w  w  .  j  a v a 2 s. c  o  m*/
    Calendar endCal = Calendar.getInstance();
    endCal.setTime(end);

    sDayNames.clear();
    sDayAbbreviations.clear();

    for (Date date = startCal.getTime(); startCal.before(endCal); startCal.add(Calendar.DATE,
            1), date = startCal.getTime()) {
        sDayNames.add(dayLabelFormatter.format(date));
        sDayAbbreviations.add(dayAbbrevFormatter.format(date));
    }
}

From source file:org.globus.workspace.service.impls.ResourceSweeper.java

public static boolean isExpired(Calendar terminationTime, Calendar currentTime) {
    return terminationTime != null && terminationTime.before(currentTime);
}

From source file:org.easycloud.las.core.util.TimeUtil.java

/**
 * Check if <code>before<code/> is before now by <code>interval<code/>
 *
 * @param time     the time to be checked
 * @param interval the intervals/*  w  ww.  j  a v a 2s. c  om*/
 * @param timeUnit the time unit of interval
 * @return true if <code>before<code/> is before now by <code>interval<code/>
 */
public static boolean isBeforeNow(Date time, int interval, int timeUnit) {
    assertArgNotNull(time, "TimeUtil isBeforeNow before null");
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(time);
    calendar.add(timeUnit, interval);
    return calendar.before(Calendar.getInstance());
}

From source file:org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils.java

/**
 * Returns the next Calendar from today.
 *//* w  w  w  .  j  a v a  2 s  .c o  m*/
public static Calendar getNext(Calendar... calendars) {
    Calendar now = Calendar.getInstance();
    Calendar next = null;
    for (Calendar calendar : calendars) {
        if (calendar.after(now) && (next == null || calendar.before(next))) {
            next = calendar;
        }
    }
    return next;
}

From source file:Main.java

public static boolean CoversFYStart(Calendar one, Calendar two, Calendar fy_start) throws Exception {
    if (one == null || two == null)
        throw new Exception("CoversFYStart: Null dates passed in");
    if (fy_start == null)
        throw new Exception("CoversFYStart: Null FY Start");

    int fy_month = fy_start.get(Calendar.MONTH);
    int fy_day = fy_start.get(Calendar.DAY_OF_MONTH);
    Calendar cal = (Calendar) one.clone();

    while (true) {
        cal.add(Calendar.DATE, 1);
        int month = cal.get(Calendar.MONTH);
        int day = cal.get(Calendar.DAY_OF_MONTH);
        if (month == fy_month && day == fy_day)
            break;
    }/*w  ww.  j  a  v  a2 s  . c  o m*/

    return cal.before(two);
}

From source file:com.xumpy.timesheets.services.implementations.JobsSrvImpl.java

public static List<? extends Jobs> addZeroDates(List<? extends Jobs> jobs, String month, JobsGroup jobsGroup)
        throws ParseException {
    SimpleDateFormat dfOnlyDay = new SimpleDateFormat("dd");
    List<Jobs> allJobsInMonth = new ArrayList<Jobs>();

    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    Date startDate = df.parse("01/" + month);

    Calendar endDate = Calendar.getInstance();
    endDate.setTime(startDate);//from  ww  w. j a  va 2 s .  com
    endDate.set(Calendar.DAY_OF_MONTH, endDate.getActualMaximum(Calendar.DAY_OF_MONTH));
    endDate.add(Calendar.DATE, 1);

    Calendar iteratorDate = Calendar.getInstance();
    iteratorDate.setTime(startDate);

    while (iteratorDate.before(endDate)) {
        boolean found = false;
        JobsSrvPojo jobsSrvPojo = new JobsSrvPojo();

        for (Jobs job : jobs) {
            if (df.format(job.getJobDate()).equals(df.format(iteratorDate.getTime()))) {
                found = true;
                jobsSrvPojo = new JobsSrvPojo(job);
            }
        }

        if (!found) {
            jobsSrvPojo.setJobDate(iteratorDate.getTime());
            jobsSrvPojo.setJobsGroup(new JobsGroupSrvPojo(jobsGroup));
            jobsSrvPojo.setWorkedHours("0");
            jobsSrvPojo.setWeekendDay(jobInWeekend(jobsSrvPojo));
        }
        jobsSrvPojo.setJobDay(dfOnlyDay.format(jobsSrvPojo.getJobDate()));
        allJobsInMonth.add(jobsSrvPojo);
        iteratorDate.add(Calendar.DATE, 1);
    }

    return allJobsInMonth;
}

From source file:org.dspace.app.statistics.CreateStatReport.java

/**
 * This script starts from the year and month specified below and loops each month until the current month
 * generating monthly reports from the DStat aggregation files
 * //from ww w .ja va  2 s . c  o  m
 * @throws Exception
 */
private static void statReportInitial() throws Exception {

    //Prefix
    String inputPrefix = "dspace-log-monthly-";
    String outputPrefix = "report-";

    String myFormat = "html";
    StringBuffer myInput = null;
    StringBuffer myOutput = null;
    String myMap = null;

    Calendar reportEndDate = new GregorianCalendar(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.getActualMaximum(Calendar.DAY_OF_MONTH));

    Calendar currentMonth = (Calendar) reportStartDate.clone();

    while (currentMonth.before(reportEndDate)) {

        myInput = new StringBuffer(outputLogDirectory);
        myInput.append(inputPrefix);
        myInput.append(currentMonth.get(Calendar.YEAR));
        myInput.append("-");
        myInput.append(currentMonth.get(Calendar.MONTH) + 1);
        myInput.append(outputSuffix);

        myOutput = new StringBuffer(outputReportDirectory);
        myOutput.append(outputPrefix);
        myOutput.append(currentMonth.get(Calendar.YEAR));
        myOutput.append("-");
        myOutput.append(currentMonth.get(Calendar.MONTH) + 1);
        myOutput.append(".");
        myOutput.append(myFormat);

        ReportGenerator.processReport(context, myFormat, myInput.toString(), myOutput.toString(), myMap);

        currentMonth.add(Calendar.MONTH, 1);
    }
}

From source file:org.dspace.app.statistics.CreateStatReport.java

/**
 * This script starts from the year and month specified below and loops each month until the current month
 * generating a monthly aggregation files for the DStat system.
 * //ww  w.  j  a  v a  2  s. c  o  m
 * @throws Exception
 */
private static void statInitial() throws Exception {

    //Output Prefix
    String outputPrefix = "dspace-log-monthly-";

    // set up our command line variables
    String myLogDir = null;
    String myFileTemplate = null;
    String myConfigFile = null;
    StringBuffer myOutFile = null;
    Date myStartDate = null;
    Date myEndDate = null;
    boolean myLookUp = false;

    Calendar reportEndDate = new GregorianCalendar(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.getActualMaximum(Calendar.DAY_OF_MONTH));

    Calendar currentMonth = (Calendar) reportStartDate.clone();
    while (currentMonth.before(reportEndDate)) {

        Calendar start = new GregorianCalendar(currentMonth.get(Calendar.YEAR),
                currentMonth.get(Calendar.MONTH), currentMonth.getActualMinimum(Calendar.DAY_OF_MONTH));
        myStartDate = start.getTime();

        Calendar end = new GregorianCalendar(currentMonth.get(Calendar.YEAR), currentMonth.get(Calendar.MONTH),
                currentMonth.getActualMaximum(Calendar.DAY_OF_MONTH));
        myEndDate = end.getTime();

        myOutFile = new StringBuffer(outputLogDirectory);
        myOutFile.append(outputPrefix);
        myOutFile.append(currentMonth.get(Calendar.YEAR));
        myOutFile.append("-");
        myOutFile.append(currentMonth.get(Calendar.MONTH) + 1);
        myOutFile.append(outputSuffix);

        LogAnalyser.processLogs(context, myLogDir, myFileTemplate, myConfigFile, myOutFile.toString(),
                myStartDate, myEndDate, myLookUp);

        currentMonth.add(Calendar.MONTH, 1);
    }
}

From source file:com.li.bus.utils.DateUtils.java

/**
 * ???//from   w  w  w  . j ava 2s  .  co m
 * @param date_begin
 * @param date_end
 * @return
 */
public static List<Date> getDates(Calendar date_begin, Calendar date_end) {
    List<Date> result = new ArrayList<Date>();
    Calendar temp = date_begin;
    while (temp.before(date_end)) {
        result.add(temp.getTime());
        temp.add(Calendar.DAY_OF_YEAR, 1);
    }
    return result;
}