List of usage examples for java.util Calendar before
public boolean before(Object when)
Calendar
represents a time before the time represented by the specified Object
. From source file:org.sipfoundry.sipxconfig.admin.CronSchedule.java
Date getFirstDate() { Calendar firstDate = Calendar.getInstance(); if (isWeekly()) { firstDate.set(Calendar.DAY_OF_WEEK, m_dayOfWeek); }/* w w w .j ava 2 s . c o m*/ if (isWeekly() || isDaily()) { firstDate.set(Calendar.HOUR_OF_DAY, m_hrs); } firstDate.set(Calendar.MINUTE, m_min); // make sure it's in the future if (firstDate.before(Calendar.getInstance())) { firstDate.add(Calendar.MILLISECOND, (int) getDelay()); } firstDate = DateUtils.round(firstDate, Calendar.MINUTE); return firstDate.getTime(); }
From source file:com.sean.takeastand.storage.ScheduleEditor.java
public void editEndTime(boolean alarmToday, AlarmSchedule alarmSchedule) { int UID = alarmSchedule.getUID(); Calendar endTime = alarmSchedule.getEndTime(); scheduleDatabaseAdapter.updateEndTime(UID, Utils.calendarToTimeString(endTime)); if (alarmToday && alarmSchedule.getActivated()) { Calendar startTime = alarmSchedule.getStartTime(); Calendar rightNow = Calendar.getInstance(); FixedAlarmSchedule fixedAlarmSchedule = new FixedAlarmSchedule(alarmSchedule); if (endTime.after(rightNow) && startTime.before(rightNow)) { ScheduledRepeatingAlarm scheduledRepeatingAlarm = new ScheduledRepeatingAlarm(mContext, fixedAlarmSchedule); scheduledRepeatingAlarm.updateAlarm(); //Update cancels the original alarm, so image needs to be set again Utils.setImageStatus(mContext, Constants.SCHEDULE_RUNNING); } else {/*from ww w . j av a 2s . co m*/ if (UID == Utils.getRunningScheduledAlarm(mContext)) { new ScheduledRepeatingAlarm(mContext, fixedAlarmSchedule).cancelAlarm(); } } } }
From source file:nl.strohalm.cyclos.entities.ads.Ad.java
public Status getStatus() { if (permanent) { return Status.PERMANENT; } else {//w ww . j a v a 2 s . co m final Calendar begin = publicationPeriod == null ? null : publicationPeriod.getBegin(); final Calendar end = publicationPeriod == null ? null : publicationPeriod.getEnd(); final Calendar now = Calendar.getInstance(); if (begin != null && begin.after(now)) { return Status.SCHEDULED; } else if (end != null && end.before(now)) { return Status.EXPIRED; } } return Status.ACTIVE; }
From source file:gr.abiss.calipso.model.dto.ReportDataSet.java
protected void initDefaults(Date dateFrom, Date dateTo, TimeUnit timeUnit, Map<String, Integer> keyIndexes, Map<String, Number> defaultDataEntry) { // init default record values, to be used in missing date slots to ensure regular records if (defaultDataEntry == null) { defaultDataEntry = new HashMap<String, Number>(); for (String key : keyIndexes.keySet()) { defaultDataEntry.put(key, new Integer(0)); }/*from www .j a v a 2s .co m*/ } // init default values for all dates in range to ensure regular records Calendar start = Calendar.getInstance(); // get start of day start.setTime(DateUtils.truncate(dateFrom, Calendar.DATE)); Calendar end = Calendar.getInstance(); // get end of day end.setTime(DateUtils.addMilliseconds(DateUtils.ceiling(dateTo, Calendar.DATE), -1)); for (Date date = start.getTime(); start.before(end); start.add(timeUnit.toCalendarUnit(), 1), date = start.getTime()) { this.addEntry(date, defaultDataEntry); } }
From source file:org.soyatec.windowsazure.blob.internal.BlobStorageRest.java
public ISharedAccessUrl createSharedAccessUrl(String containerName, String blobName, ResourceType resource, int permissions, DateTime start, DateTime expiry, String identifier) throws StorageServerException { if (Utilities.isNullOrEmpty(containerName)) { throw new IllegalArgumentException("Container name cannot be null or empty!"); }/* www . j av a 2 s. c om*/ if (!Utilities.isValidContainerOrQueueName(containerName)) { throw new IllegalArgumentException(MessageFormat.format( "The specified container name \"{0}\" is not valid!" + "\nPlease choose a name that conforms to the naming conventions for containers!", containerName)); } if (identifier == null && start != null && expiry != null) { Calendar calendar = start.toCalendar(); calendar.add(Calendar.HOUR_OF_DAY, 1); if (calendar.before(expiry.toCalendar())) { throw new IllegalArgumentException( "Access without signed identifier cannot have time window more than 1 hour"); } } ISharedAccessUrl result = new SharedAccessUrl(); result.setAccountName(getAccountName()); String resourceName = containerName; if (blobName != null) { resourceName += "/" + blobName; } StringBuilder buf = new StringBuilder(); try { if (start != null) { buf.append("st=").append(urlencode(start.toString())).append("&"); } buf.append("se=").append(urlencode(expiry.toString())).append("&"); buf.append("sr=").append(resource.toString()).append("&"); if (permissions != SharedAccessPermissions.NONE) { buf.append("sp=").append(SharedAccessPermissions.toString(permissions)).append("&"); } if (identifier != null) { buf.append("si=").append(identifier).append("&"); } String canonicalizedResource = "/" + getAccountName(); if (isUsePathStyleUris()) { canonicalizedResource += "/" + getAccountName(); } canonicalizedResource += "/" + resourceName; String signature = credentials.signSharedAccessUrl(SharedAccessPermissions.toString(permissions), start == null ? null : start.toString(), expiry == null ? null : expiry.toString(), canonicalizedResource, identifier); buf.append("sig=").append(urlencode(signature)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ResourceUriComponents uriComponents = new ResourceUriComponents(getAccountName(), "", null); URI containerUri = HttpRequestAccessor.constructResourceUri(getBaseUri(), uriComponents, isUsePathStyleUris()); result.setRestUrl(containerUri.toString() + "/" + resourceName); result.setSignedString(buf.toString()); // return containerUri.toString() + "/" + resourceName + "?" + // buf.toString(); return result; }
From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java
/** * Generate the histogram buckets based on the time frame requested and the interval. This will * add an entry for each 'slot' or 'bucket' in the histogram, setting the count to 0. * @param rval// w ww. j a va 2 s .c om * @param from * @param to * @param interval */ public static <T extends HistogramDataPoint, K> Map<K, T> generateHistogramSkeleton(HistogramBean<T> rval, DateTime from, DateTime to, HistogramIntervalType interval, Class<T> dataType, Class<K> keyType) { Map<K, T> index = new HashMap<>(); Calendar fromCal = from.toGregorianCalendar(); Calendar toCal = to.toGregorianCalendar(); switch (interval) { case day: fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case hour: fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case minute: fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case month: fromCal.set(Calendar.DAY_OF_MONTH, 1); fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case week: fromCal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; default: break; } while (fromCal.before(toCal)) { String label = formatDateWithMillis(fromCal); T point; try { point = dataType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } point.setLabel(label); rval.addDataPoint(point); if (keyType == String.class) { index.put((K) label, point); } else { index.put((K) new Long(fromCal.getTimeInMillis()), point); } switch (interval) { case day: fromCal.add(Calendar.DAY_OF_YEAR, 1); break; case hour: fromCal.add(Calendar.HOUR_OF_DAY, 1); break; case minute: fromCal.add(Calendar.MINUTE, 1); break; case month: fromCal.add(Calendar.MONTH, 1); break; case week: fromCal.add(Calendar.WEEK_OF_YEAR, 1); break; default: break; } } return index; }
From source file:is.idega.idegaweb.egov.gumbo.licenses.SetDraganotveidiValidPeriod.java
public void execute(ExecutionContext executionContext) throws Exception { final Interval period; final Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR, 0);// ww w . jav a 2 s. co m now.set(Calendar.MINUTE, 0); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); final Calendar mayStart = Calendar.getInstance(); mayStart.set(now.get(Calendar.YEAR), Calendar.MAY, 1, 0, 0, 0); final Calendar augEnd = Calendar.getInstance(); augEnd.set(now.get(Calendar.YEAR), Calendar.AUGUST, 31, 0, 0, 0); if (now.after(mayStart) && now.before(augEnd)) { period = new Interval(now.getTime(), augEnd.getTime()); } else { period = findNearestPeriod(now); } executionContext.setVariable("date_validityFrom", period.getFrom()); executionContext.setVariable("date_validityTo", period.getTo()); }
From source file:mchs.neverforget.services.NotificationIntentService.java
private void handleActionNotify() { //Toast.makeText(this, "handleActionNotify", Toast.LENGTH_LONG).show(); bookArrayList = new ArrayList<>(); NeverForgetDatabaseAdapter databaseAdapter = new NeverForgetDatabaseAdapter(this); bookArrayList.addAll(databaseAdapter.getBooks()); @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy"); int expiredCounter = 0; int aboutToExpireCounter = 0; int i = 0;//from w w w . j a v a 2 s. c o m boolean[] expiredFlags = new boolean[bookArrayList.size()]; String[] titles = new String[bookArrayList.size()]; for (Book b : bookArrayList) { Calendar returnDate = new GregorianCalendar(); Calendar currentDate = new GregorianCalendar(); try { returnDate.setTime(sdf.parse(b.getReturnDate())); currentDate.setTime(sdf.parse(sdf.format(System.currentTimeMillis()))); if (returnDate.before(currentDate)) { expiredCounter++; expiredFlags[i] = true; titles[i] = b.getTitle(); } else { int days = NeverForgetActivity.daysBetween(returnDate, currentDate); if (days < 5) { aboutToExpireCounter++; titles[i] = b.getTitle(); } } } catch (ParseException e) { e.printStackTrace(); } i++; } if (aboutToExpireCounter > 0 || expiredCounter > 0) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent subActivityIntent = new Intent(this, NeverForgetActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack stackBuilder.addParentStack(NeverForgetActivity.class); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(subActivityIntent); // Gets a PendingIntent containing the entire back stack PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); String contentText = null; if (expiredCounter + aboutToExpireCounter == 1) { int index = 0; for (int j = 0; j < titles.length; j++) { if (titles[j] != null) { contentText = titles[j]; index = j; } } if (expiredCounter == 1) { contentText = "(EXPIRADO)" + contentText; } else { contentText = bookArrayList.get(index).getReturnDate() + " - " + contentText; } } else { contentText = (expiredCounter + aboutToExpireCounter) + " livros requerem sua ateno"; notificationBuilder.setStyle(setupInboxStyle(titles, expiredFlags)); } String ringtonePreferenceString = PreferenceManager.getDefaultSharedPreferences(this) .getString("notification_ringtone", "DEFAULT_SOUND"); notificationBuilder.setTicker("Hey. Voc precisa dar uma espiada nos seus emprstimos") .setAutoCancel(true).setContentTitle("Never Forget").setContentText(contentText) .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_stat_item_book) .setSound(Uri.parse(ringtonePreferenceString)); boolean shouldVibrate = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("notifications_vibrate", true); if (shouldVibrate) { notificationBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000 }); } notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); } }
From source file:com.predic8.membrane.core.exchangestore.FileExchangeStore.java
public void initializeTimer() { if (this.maxDays < 0) { return; // don't do anything if this feature is deactivated }/*from w w w . j av a 2 s. com*/ oldFilesCleanupTimer = new Timer("Clean up old log files", true); // schedule first run for the night Calendar firstRun = Calendar.getInstance(); firstRun.set(Calendar.HOUR_OF_DAY, 3); firstRun.set(Calendar.MINUTE, 14); // schedule for the next day if the scheduled execution time is before now if (firstRun.before(Calendar.getInstance())) firstRun.add(Calendar.DAY_OF_MONTH, 1); oldFilesCleanupTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { deleteOldFolders(); } catch (IOException e) { log.error("", e); } } }, firstRun.getTime(), 24 * 60 * 60 * 1000 // one day ); }
From source file:nl.strohalm.cyclos.utils.Period.java
/** * Checks whether the given date is included in this period. When the useTime flag is true, the time of the parameter (date) and the time of the * begin and end dates of the period are taken into account to compute the result. If the exact begin date/time is included depends on the * <code>inclusiveBegin</code> flag; by default, this is true, so begin date/time is considered to be <strong>included</strong> in the period. If * the exact end date/time is included depends on the <code>inclusiveEnd</code> flag; which behaves in the same way as the inclusiveBegin flag. * Both are true by default.<br>/* w w w .java 2 s .com*/ * When the useTime flag is false, the dates are truncated to compute the result, and the inclusiveBegin and inclusiveEnd flags are ignored. */ public boolean includes(final Calendar date) { if (date == null) { return false; } else if (begin == null && end == null) { return true; } else { if (useTime) { if (begin == null) { return (inclusiveEnd) ? !end.before(date) : date.before(end); } else if (end == null) { return (inclusiveBegin) ? !date.before(begin) : begin.before(date); } else { final boolean beginOK = (inclusiveBegin) ? !date.before(begin) : begin.before(date); final boolean endOK = (inclusiveEnd) ? !end.before(date) : date.before(end); return beginOK && endOK; } } else { final Calendar tDate = DateUtils.truncate(date, Calendar.DATE); Calendar tBegin = begin; Calendar tEnd = end; if (begin != null) { tBegin = DateUtils.truncate(begin, Calendar.DATE); } if (end != null) { // If not using time, we'll assume the end of the interval is // the instant before the next day. tEnd = DateHelper.truncateNextDay(end); } if (tBegin == null) { // it's included if the date is an instant before the next day. return tDate.before(tEnd); } else if (tEnd == null) { // it's included if the date is not before the begin return !tDate.before(tBegin); } else { return !tDate.before(tBegin) && tDate.before(tEnd); } } } }