Java Code Examples for java.util.GregorianCalendar#before()

The following examples show how to use java.util.GregorianCalendar#before() . 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: DateUtil.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private static boolean isDateForImmediateAction(Date actionDate) {
   	// Create the calendar object for comparison
       GregorianCalendar now = new GregorianCalendar();
       GregorianCalendar actionDateCalendar = new GregorianCalendar();

       // Set the time of the test-calendar
       actionDateCalendar.setTime(actionDate);

       // Move "current time" 5 minutes into future, so we get a 5 minute fairness period
       now.add( Calendar.MINUTE, 5);
       
       // Do the hard work!
       return !now.before(actionDateCalendar);
}
 
Example 2
Source File: DateUtil.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
public static boolean isValidSendDate( Date sendDate) {
	// Create the calendar object for comparison
    GregorianCalendar now = new GregorianCalendar();
    GregorianCalendar sendDateCalendar = new GregorianCalendar();

    // Set the time of the test-calendar
    sendDateCalendar.setTime( sendDate);

    // Move "current time" 5 minutes into future, so we get a 5 minute fairness period
    now.add( Calendar.MINUTE, -5);
    
    // Do the hard work!
    return now.before( sendDateCalendar);
}
 
Example 3
Source File: TimeBasedDataSet.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
protected List<TimeBasedClickStatRow> getTimeBasedClickStat(List<DeviceClass> deviceClassesForDisplay,
															Map<Integer, LightTarget> targetGroups, Map<Integer, Integer> targetGroupIndexes,
															GregorianCalendar nextPeriodDate, GregorianCalendar endPeriodDate, boolean hourly) {
	List<TimeBasedClickStatRow> returnList = new ArrayList<>();
	while (nextPeriodDate.before(endPeriodDate)) {
		for (Map.Entry<Integer, LightTarget> targetEntry : targetGroups.entrySet()) {
			for (DeviceClass deviceClass : deviceClassesForDisplay) {
				boolean found = false;
				for (TimeBasedClickStatRow entry : returnList) {
					if (entry.getClickTime().equals(nextPeriodDate.getTime()) && entry.getDeviceClass() == deviceClass) {
						found = true;
						break;
					}
				}
				if (!found) {
					TimeBasedClickStatRow timeBasedClickStatRow = new TimeBasedClickStatRow();
					timeBasedClickStatRow.setClickTime(nextPeriodDate.getTime());
					timeBasedClickStatRow.setClicks_net(0);
					timeBasedClickStatRow.setDeviceClass(deviceClass);
					timeBasedClickStatRow.setTargetgroup(targetGroups.get(targetEntry.getKey()) == null ?
							CommonKeys.ALL_SUBSCRIBERS : targetGroups.get(targetEntry.getKey()).getName());
					timeBasedClickStatRow.setColumn_index(targetGroupIndexes.get(targetEntry.getKey()));
					returnList.add(timeBasedClickStatRow);
				}
			}
		}
		
		nextPeriodDate.add(hourly ? Calendar.HOUR_OF_DAY : Calendar.DAY_OF_MONTH, 1);
	}
	
	return returnList;
}
 
Example 4
Source File: CalendarRegression.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void Test4035301() {
    GregorianCalendar c = new GregorianCalendar(98, 8, 7);
    GregorianCalendar d = new GregorianCalendar(98, 8, 7);
    if (c.after(d)
            || c.after(c)
            || c.before(d)
            || c.before(c)
            || !c.equals(c)
            || !c.equals(d)) {
        errln("Fail");
    }
}
 
Example 5
Source File: DateUtils.java    From wasindoor with Apache License 2.0 5 votes vote down vote up
/**
 * 获取任意两个日期间的天数
 * @param tStartDate 起始日期,
 * @param tEndDate  结束日期
 * @return 天数
 */
public static int getDayCount(Date tStartDate, Date tEndDate) {
    int iRetVal = 0;
    GregorianCalendar calendar = (GregorianCalendar) GregorianCalendar.
                                 getInstance();
    calendar.setTime(tStartDate);
    GregorianCalendar calendar2 = (GregorianCalendar) GregorianCalendar.
                                  getInstance();
    calendar2.setTime(tEndDate);
    int iMaxDays = 0;

    while (calendar.before(calendar2)) {
        if (calendar.isLeapYear(calendar.get(GregorianCalendar.YEAR))) {
            iMaxDays = 366;
        } else {
            iMaxDays = 365;
        }
        ++iRetVal;
        calendar.roll(GregorianCalendar.DAY_OF_YEAR, true);

        if (calendar.get(GregorianCalendar.DAY_OF_YEAR) == iMaxDays) {
            calendar.roll(GregorianCalendar.YEAR, 1);
            calendar.set(GregorianCalendar.MONTH, GregorianCalendar.JANUARY);
            calendar.set(GregorianCalendar.DAY_OF_MONTH, 1);
        }
    }
    return iRetVal;
}
 
Example 6
Source File: FavoritesNotifier.java    From 4pdaClient-plus with Apache License 2.0 5 votes vote down vote up
private boolean hasUnreadNotify(ArrayList<FavTopic> topics){

        if (topics.size() == 0 || getNewTopicsCount(topics) == 0)
            return false;

        Topic lastPostedTopic = null;
        for (FavTopic topic : topics) {
            if (topic.getIsNew() && (!m_PinnedOnly || topic.isPinned())) {
                lastPostedTopic = topic;
                break;
            }
        }

        if (lastPostedTopic == null || !lastPostedTopic.getIsNew())
            return false;

        GregorianCalendar lastPostedTopicCalendar = new GregorianCalendar();
        lastPostedTopicCalendar.setTime(lastPostedTopic.getLastMessageDate());


        GregorianCalendar lastDateTime = loadLastDate(LAST_DATETIME_KEY);

        if (lastDateTime == null || lastDateTime.before(lastPostedTopicCalendar)) {
            saveLastDate(lastPostedTopicCalendar, LAST_DATETIME_KEY);
            return true;
        }
        return false;
    }
 
Example 7
Source File: KeyGeneratorTimer.java    From oxAuth with MIT License 5 votes vote down vote up
private JSONObject updateKeys(JSONObject jwks) throws Exception {
    JSONObject jsonObject = AbstractCryptoProvider.generateJwks(cryptoProvider, appConfiguration.getKeyRegenerationInterval(),
            appConfiguration.getIdTokenLifetime(), appConfiguration);

    JSONArray keys = jwks.getJSONArray(JSON_WEB_KEY_SET);
    for (int i = 0; i < keys.length(); i++) {
        JSONObject key = keys.getJSONObject(i);

        if (key.has(EXPIRATION_TIME) && !key.isNull(EXPIRATION_TIME)) {
            GregorianCalendar now = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
            GregorianCalendar expirationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
            expirationDate.setTimeInMillis(key.getLong(EXPIRATION_TIME));

            if (expirationDate.before(now)) {
                // The expired key is not added to the array of keys
                log.trace("Removing JWK: {}, Expiration date: {}", key.getString(KEY_ID),
                        key.getLong(EXPIRATION_TIME));
                cryptoProvider.deleteKey(key.getString(KEY_ID));
            } else if (cryptoProvider.containsKey(key.getString(KEY_ID))) {
                log.trace("Contains kid: {}", key.getString(KEY_ID));
                jsonObject.getJSONArray(JSON_WEB_KEY_SET).put(key);
            }
        } else if (cryptoProvider.containsKey(key.getString(KEY_ID))) {
            GregorianCalendar expirationTime = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
            expirationTime.add(GregorianCalendar.HOUR, appConfiguration.getKeyRegenerationInterval());
            expirationTime.add(GregorianCalendar.SECOND, appConfiguration.getIdTokenLifetime());
            key.put(EXPIRATION_TIME, expirationTime.getTimeInMillis());

            log.trace("Contains kid {} without exp {}", key.getString(KEY_ID), expirationTime);

            jsonObject.getJSONArray(JSON_WEB_KEY_SET).put(key);
        }
    }

    return jsonObject;
}