Example usage for java.util GregorianCalendar after

List of usage examples for java.util GregorianCalendar after

Introduction

In this page you can find the example usage for java.util GregorianCalendar after.

Prototype

public boolean after(Object when) 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] a) {
    GregorianCalendar today = new GregorianCalendar();
    GregorianCalendar thisDate = new GregorianCalendar();
    thisDate.set(Calendar.YEAR, 2000);
    if (thisDate.before(today)) {
        System.out.println("before");
    }//from  w ww.  j a  v a 2s.  c  o  m
    if (today.after(thisDate)) {
        System.out.println("after");
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    GregorianCalendar birthdate = new GregorianCalendar(1999, 1, 1);
    GregorianCalendar today = new GregorianCalendar(); // Today's date
    GregorianCalendar birthday = new GregorianCalendar(today.get(YEAR), birthdate.get(MONTH),
            birthdate.get(DATE));/*from  www .  j  av  a 2  s .c om*/
    int age = today.get(today.YEAR) - birthdate.get(YEAR);
    String[] weekdays = new DateFormatSymbols().getWeekdays(); // Get day names
    System.out.println("You were born on a " + weekdays[birthdate.get(DAY_OF_WEEK)]);
    System.out.println("This year you " + (birthday.after(today) ? " will be " : "are ") + age + " years old.");
    System.out
            .println("In " + today.get(YEAR) + " your birthday " + (today.before(birthday) ? "will be" : "was")
                    + " on a " + weekdays[birthday.get(DAY_OF_WEEK)] + ".");
}

From source file:TimeLib.java

/**
 * Get the number of time units between the two given timestamps.
 * @param t0 the first timestamp (as a long)
 * @param t1 the second timestamp (as a long)
 * @param field the time unit to use, one of the {@link java.util.Calendar}
 * fields, or one of the extended fields provided by this class
 * (MILLENIUM, CENTURY, or DECADE)./*from w  w  w.ja va2 s .c  o  m*/
 * @return the number of time units between the two timestamps
 */
public static int getUnitsBetween(long t0, long t1, int field) {
    boolean negative = false;
    if (t1 < t0) {
        long tmp = t1;
        t1 = t0;
        t0 = tmp; // swap
        negative = true;
    }
    GregorianCalendar gc1 = new GregorianCalendar();
    GregorianCalendar gc2 = new GregorianCalendar();
    gc1.setTimeInMillis(t0);
    gc2.setTimeInMillis(t1);

    // add 2 units less than the estimate to 1st date,
    // then serially add units till we exceed 2nd date
    int est = estimateUnitsBetween(t0, t1, field);
    boolean multiYear = isMultiYear(field);
    if (multiYear) {
        gc1.add(Calendar.YEAR, -field * (est - 2));
        est = -field * est;
    } else {
        gc1.add(field, est - 2);
    }
    int f = multiYear ? Calendar.YEAR : field;
    int inc = multiYear ? -field : 1;
    for (int i = est - inc;; i += inc) {
        gc1.add(f, inc);
        if (gc1.after(gc2)) {
            return negative ? inc - i : i - inc;
        }
    }
}

From source file:no.dusken.aranea.service.IssueServiceImpl.java

public List<Issue> getIssuesPublished(int year) {
    List<Issue> i = Collections.emptyList();
    try {//from  w w w . j a  v  a 2  s  .co  m
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("fromDate", new GregorianCalendar(year, 0, 1));
        GregorianCalendar endOfYear = new GregorianCalendar(year, 11, 31);
        GregorianCalendar today = new GregorianCalendar();
        if (endOfYear.after(today)) {
            map.put("toDate", today);
        } else {
            map.put("toDate", endOfYear);
        }
        i = genericDao.getByNamedQuery("issues_byyear_published", map);
    } catch (DataAccessException dae) {
        log.warn("Unable to get Issues", dae);
    }
    return i;
}

From source file:org.oscarehr.web.MisReportUIBean.java

private int calculateResidentDays(Admission admission) {
    GregorianCalendar startBound = startDate;
    if (startBound.before(admission.getAdmissionCalendar()))
        startBound = admission.getAdmissionCalendar();

    GregorianCalendar endBound = endDate;
    if (endBound.after(admission.getDischargeCalendar()))
        endBound = admission.getDischargeCalendar();

    return (DateUtils.calculateDayDifference(startBound, endBound));
}

From source file:org.nuxeo.ecm.platform.forum.web.ThreadActionBean.java

public DocumentModel getLastPostPublished(DocumentModel thread) throws ClientException {

    thread = getDocumentThreadModel(thread.getRef());
    List<DocumentModel> posts = getPostsPublished(thread);
    DocumentModel lastPost = null;/*from   ww  w . j  av  a  2  s. co m*/
    if (!posts.isEmpty()) {
        lastPost = posts.get(0);
        for (DocumentModel post : posts) {
            GregorianCalendar lastPostDate = (GregorianCalendar) lastPost.getProperty("post", "creationDate");
            GregorianCalendar postDate = (GregorianCalendar) post.getProperty("post", "creationDate");
            if (postDate != null && postDate.after(lastPostDate)) {
                lastPost = post;
            }
        }

    }
    return lastPost;
}

From source file:org.colombbus.tangara.Main.java

private static void checkForUpdate() {
    Configuration conf = Configuration.instance();
    // Check for updates if the feature is enabled in conf
    if (conf.getInteger("checkUpdate.activation") == 1) {
        boolean checkUpdate = false;
        GregorianCalendar today = new GregorianCalendar();
        GregorianCalendar lastLaunch = new GregorianCalendar();
        lastLaunch.setTimeInMillis(0);//from w  w  w  .  j  ava2s  . c o  m
        Properties properties = conf.loadUpdateProperties();

        // Read last Launch date
        if ((properties != null) && (properties.containsKey("checkUpdate.lastLaunch"))) {
            String strValue = properties.getProperty("checkUpdate.lastLaunch");
            long longValue = Long.parseLong(strValue);
            lastLaunch.setTimeInMillis(longValue);
        } else {
            LOG.warn("Failed to load lastLaunch property");
            properties = new Properties();
        }

        // Write last Launch date
        properties.setProperty("checkUpdate.lastLaunch", Long.toString(today.getTimeInMillis()));
        conf.saveUpdateProperties(properties);

        String intervalText = Configuration.instance().getProperty("checkUpdate.interval");
        if (intervalText.equals("ALWAYS")) {
            checkUpdate = true;
        } else if (intervalText.equals("WEEK")) {
            lastLaunch.add(GregorianCalendar.DAY_OF_MONTH, 7);
            checkUpdate = (today.after(lastLaunch));
        } else if (intervalText.equals("MONTH")) {
            lastLaunch.add(GregorianCalendar.MONTH, 1);
            checkUpdate = (today.after(lastLaunch));
        }
        if (checkUpdate) {
            SoftwareUpdate.launchVersionCheck();
        }
    }
}

From source file:net.urlgrey.mythpodcaster.transcode.IndividualFeedTranscodeTaskImpl.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//from w ww. ja  va  2 s  .  c  o m
public void run() {
    if (subscription.isActive()) {
        // identify series recordings not represented in the RSS Feed (transcode)
        final List entries = feed.getEntries();
        final RecordedSeries series;
        if (ScopeEnum.MOST_RECENT.equals(subscription.getScope())) {
            series = recordingsDao.findRecordedSeries(subscription.getSeriesId(),
                    subscription.getNumberOfMostRecentToKeep());
        } else {
            series = recordingsDao.findRecordedSeries(subscription.getSeriesId());
        }

        if (series == null) {
            // if not occurrences of the recorded series are found, then continue
            LOGGER.debug("No recordings found for recordId[" + subscription.getSeriesId() + "]");
        }

        if (series != null) {
            for (RecordedProgram program : series.getRecordedPrograms()) {
                if (program.getEndTime() == null) {
                    LOGGER.debug("Skipping program, end-time is not set (possibly still recording): programId["
                            + program.getProgramId() + "]");
                    continue;
                }

                // We should determine whether the program is finished.
                // This can be determine by comparing the program end-time with the current time (the
                // comparison must use the same timezone for both dates)
                // See http://code.google.com/p/mythpodcaster/issues/detail?id=65
                final GregorianCalendar programCal = new GregorianCalendar();
                programCal.setTimeInMillis(program.getEndTime().getTime());
                final GregorianCalendar localTimeCal = new GregorianCalendar();
                if (programCal.after(localTimeCal)) {
                    LOGGER.debug(
                            "Skipping recorded program, end-time is in future (still recording): programId["
                                    + program.getProgramId() + "]");
                    continue;
                }

                if (ScopeEnum.SPECIFIC_RECORDINGS.equals(this.subscription.getScope())
                        && (false == this.subscription.getRecordedProgramKeys().contains(program.getKey()))) {
                    LOGGER.debug(
                            "Skipping recorded program, not specified as a recording to transcode for this subscription: key["
                                    + program.getKey() + "]");
                    continue;
                }

                boolean found = false;
                LOGGER.debug("Locating program in existing feed entries: programId[" + program.getProgramId()
                        + "], key[" + program.getKey() + "]");
                if (entries != null && entries.size() > 0) {
                    final Iterator it = entries.iterator();
                    while (it.hasNext()) {
                        final SyndEntry entry = (SyndEntry) it.next();
                        if (entry.getUri() == null) {
                            continue;
                        }

                        String entryKey = entry.getUri();
                        if (program.getKey().equalsIgnoreCase(entryKey)) {
                            found = true;
                            break;
                        }
                    }
                }

                if (found) {
                    LOGGER.debug("Program was found in feed, continuing");
                } else {
                    status.setTranscodingProfileName(transcodingProfilesDao.findAllProfiles()
                            .get(subscription.getTranscodeProfile()).getDisplayName());
                    status.setTranscodingProgramEpisodeName(program.getKey());
                    status.setTranscodingSeriesTitle(series.getTitle());
                    status.setTranscodingProgramName(program.getProgramTitle());
                    status.setCurrentTranscodeStart(new Date());

                    final Channel channel = this.recordingsDao
                            .findChannel(program.getRecordedProgramKey().getChannelId());
                    feedFileAccessor.addProgramToFeed(series, program, channel, feed,
                            subscription.getTranscodeProfile());
                    writeFeedFile(entries);
                    status.setCurrentTranscodeStart(null);
                }
            }
        }

        // identify RSS Feed entries no longer in the database (delete)
        if (entries != null && entries.size() > 0) {
            LOGGER.debug("Identifying series recordings no longer in database but still in feed, recordId["
                    + subscription.getSeriesId() + "]");
            final Map<String, TranscodingProfile> transcodingProfiles = transcodingProfilesDao
                    .findAllProfiles();
            Set<SyndEntry> entryRemovalSet = new HashSet<SyndEntry>();
            final Iterator it = entries.iterator();
            while (it.hasNext()) {
                final SyndEntry entry = (SyndEntry) it.next();
                if (entry.getUri() == null) {
                    entryRemovalSet.add(entry);
                    LOGGER.debug("Feed entry has null URI (GUID), removing because it cannot be identified");
                    continue;
                }

                // locate the feed entry in the list of recorded programs
                String episodeKey = entry.getUri();
                boolean found = false;
                if (series != null) {
                    for (RecordedProgram program : series.getRecordedPrograms()) {
                        if (program.getKey().equalsIgnoreCase(episodeKey)) {
                            found = true;
                            break;
                        }
                    }
                }

                // for a feed using specific recordings, delete those entries that are no longer required
                if (ScopeEnum.SPECIFIC_RECORDINGS.equals(subscription.getScope())
                        && false == subscription.getRecordedProgramKeys().contains(episodeKey)) {
                    found = false;
                }

                // if the feed entry is no longer in the list of recorded programs, then remove
                if (found) {
                    LOGGER.debug("Feed entry is current, continuing: uid[" + entry.getUri() + "]");
                } else {
                    LOGGER.debug("Feed entry will be deleted: uid[" + entry.getUri() + "]");
                    entryRemovalSet.add(entry);

                    final List enclosures = entry.getEnclosures();
                    if (enclosures.size() > 0) {
                        final SyndEnclosure enclosure = (SyndEnclosure) enclosures.get(0);

                        final TranscodingProfile transcodingProfile = transcodingProfiles
                                .get(subscription.getTranscodeProfile());
                        transcodingProfile.deleteEncoding(this.feedFilePath, enclosure.getUrl(),
                                entry.getUri());
                    } else {
                        LOGGER.info("No enclosures specified in the entry, removing from feed and continuing");
                    }
                }
            }

            // remove all of the entries flagged for removal
            entries.removeAll(entryRemovalSet);
            writeFeedFile(entries);
        }
    }
}

From source file:com.mb.framework.util.DateTimeUtil.java

/**
 * Method called to check whether the specified date is after the current
 * date.//  w w w  .j a  v  a 2  s . c o  m
 * 
 * @param firstDt
 *            the Calendar to be compared with the specified Calendar
 * @param secondDt
 *            the Calendar to be compared with the specified Calendar
 * @return <code>true</code> if firstDt is after secondDt <code>false</code>
 *         otherwise
 */
public static boolean isAfterDate(GregorianCalendar firstDt, GregorianCalendar secondDt) {
    boolean isAfterDate = false;
    if (!isEqualDate(firstDt, secondDt)) {
        isAfterDate = firstDt.after(secondDt);
    }

    return isAfterDate;
}

From source file:org.jamwiki.servlets.PasswordResetServlet.java

private boolean isChallengeOk(HttpServletRequest request, WikiPageInfo pageInfo, WikiUser user,
        String challenge) throws Exception {
    int timeout = Environment.getIntValue(Environment.PROP_EMAIL_SERVICE_FORGOT_PASSWORD_CHALLENGE_TIMEOUT);
    if (user.getChallengeValue() != null && user.getChallengeDate() != null && user.getChallengeIp() != null) {
        // compute some deadlines
        GregorianCalendar currentDate = new GregorianCalendar();
        GregorianCalendar challengeExpires = new GregorianCalendar();
        challengeExpires.setTimeInMillis(user.getChallengeDate().getTime());
        challengeExpires.add(Calendar.MINUTE, timeout);
        if (!user.getChallengeValue().equals(challenge)) {
            pageInfo.addError(new WikiMessage("password.reset.password.error.challenge.nok"));
        } else if (currentDate.after(challengeExpires)) {
            pageInfo.addError(new WikiMessage("password.reset.password.error.challenge.expired"));
            resetChallengeData(user);//w  w w .ja va 2 s.c om
        } else {
            resetChallengeData(user);
            return true;
        }
    } else {
        pageInfo.addError(new WikiMessage("password.reset.password.error.challenge.nok"));
    }
    return false;
}