List of usage examples for org.joda.time DateTime plus
public DateTime plus(ReadablePeriod period)
From source file:com.facebook.stats.CompositeGaugeCounter.java
License:Apache License
/** * mirrors AbstractCompositeCounter:add() *//*from ww w . j a v a 2s . c om*/ @Override public void add(long delta, long nsamples) { DateTime now = new DateTime(); GaugeCounter last; synchronized (this) { if (getMostRecentCounter() == null || !now.isBefore(getMostRecentCounter().getEnd())) { addEventCounter(nextCounter(now, now.plus(getMaxChunkLength()))); } last = getMostRecentCounter(); } last.add(delta, nsamples); }
From source file:com.facebook.util.TimeInterval.java
License:Apache License
/** * Gets the start instant of the time interval that will contain the * supplied time instant. Note that the time zone of the supplied instant * plays a significant role in computation of the interval. * * @param instant the time instant//w ww . j av a2s .c o m * * @return the start instant of the time interval that will contain the * instant in the time zone of the supplied instant. If the TimeInterval is INFINITE * unix epoch for the timezone is returned. */ public DateTime getIntervalStart(DateTime instant) { // special handling for ZERO and INFINITE if (this == ZERO) { return instant; } else if (this == INFINITE) { return new DateTime(1970, 1, 1, 0, 0, 0, 0, instant.getZone()); } if (type == null) { // unix epoch for the timezone. DateTime startOfTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, instant.getZone()); long intervalStart = ((instant.getMillis() - startOfTime.getMillis()) / length) * length; return startOfTime.plus(intervalStart); } else { return type.getTimeIntervalStart(instant, length); } }
From source file:com.facebook.util.TimeInterval.java
License:Apache License
/** * Adds supplied multiples of this interval to the supplied instant. * * @param instant the instant that needs to be added to. * @param multiple the multiple value/*from www.ja v a2 s . c o m*/ * @throws IllegalArgumentException if multiple is less than one. * @throws UnsupportedOperationException if the function is invoked on an {@link #INFINITE} * object * */ public DateTime plus(DateTime instant, int multiple) { if (this == INFINITE) { throw new IllegalStateException("plus() function is not supported on an infinite TimeInterval"); } else if (this == ZERO) { return instant; } validateMultiple(multiple); if (type == null) { return instant.plus(multiple * getLength()); } else { return instant.plus(type.toPeriod(FieldUtils.safeMultiplyToInt(multiple, getLength()))); } }
From source file:com.github.dbourdette.otto.data.SimpleDataTable.java
License:Apache License
public void setupRows(Interval interval, Duration step) { rows.clear();//from w w w . j a va 2s . c o m DateTime current = interval.getStart(); while (current.isBefore(interval.getEnd())) { rows.add(new SimpleDataTableRow(new Interval(current, step))); current = current.plus(step); } }
From source file:com.github.richardwilly98.esdms.services.AuthenticationProvider.java
License:Open Source License
private void validateSession(SessionImpl session) throws ServiceException { long timeout = session.getTimeout(); if (timeout != 0) { DateTime lastAccessTime = new DateTime(session.getLastAccessTime().getTime()); DateTime timeoutTime = lastAccessTime.plus(timeout); if (timeoutTime.isBeforeNow()) { throw new ServiceException(String.format("Session %s has timed-out", session.getId())); }/*from w w w. j ava 2 s . c o m*/ } }
From source file:com.google.jenkins.plugins.cloudbackup.trigger.PeriodicBackupTrigger.java
License:Open Source License
@Override public boolean shouldCreateBackup(DateTime lastBackupTime) { DateTime nextBackupTime = lastBackupTime.plus(interval); return nextBackupTime.isBeforeNow() || nextBackupTime.isEqualNow(); }
From source file:com.groupon.lex.metrics.lib.SkippingIterator.java
private void fixup_next_() { while (next_ == null && underlying_.hasNext()) { final T next = underlying_.next(); final DateTime next_ts = timestamp_fn_.apply(next); if (!next_ts.isBefore(expected_ts_)) { next_ = next;//from w w w .j av a 2s . c o m expected_ts_ = next_ts.plus(stepsize_); } } }
From source file:com.gst.infrastructure.reportmailingjob.service.ReportMailingJobWritePlatformServiceImpl.java
License:Apache License
/** * create the next recurring DateTime from recurrence pattern, start DateTime and current DateTime * /*from w w w . j a v a 2 s . c o m*/ * @param recurrencePattern * @param startDateTime * @return DateTime object */ private DateTime createNextRecurringDateTime(final String recurrencePattern, final DateTime startDateTime) { DateTime nextRecurringDateTime = null; // the recurrence pattern/rule cannot be empty if (StringUtils.isNotBlank(recurrencePattern) && startDateTime != null) { final LocalDate nextDayLocalDate = startDateTime.plus(1).toLocalDate(); final LocalDate nextRecurringLocalDate = CalendarUtils.getNextRecurringDate(recurrencePattern, startDateTime.toLocalDate(), nextDayLocalDate); final String nextDateTimeString = nextRecurringLocalDate + " " + startDateTime.getHourOfDay() + ":" + startDateTime.getMinuteOfHour() + ":" + startDateTime.getSecondOfMinute(); final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(DATETIME_FORMAT); nextRecurringDateTime = DateTime.parse(nextDateTimeString, dateTimeFormatter); } return nextRecurringDateTime; }
From source file:com.huffingtonpost.chronos.util.CronExpression.java
License:Apache License
public DateTime nextTimeAfter(DateTime afterTime, long durationInMillis) { // will search for the next time within the next durationInMillis // millisecond. Be aware that the duration is specified in millis, // but in fact the limit is checked on a day-to-day basis. return nextTimeAfter(afterTime, afterTime.plus(durationInMillis)); }
From source file:com.karthikb351.vitinfo2.utility.DateTimeCalender.java
License:Open Source License
public static Date getTodayTimeObject(String jsonString) throws ParseException { DateFormat dateFormat = new SimpleDateFormat(Constants.JSON_ISO8601_TIME_FORMAT, Locale.US); DateTime today = new DateTime().withTimeAtStartOfDay(); dateFormat.setTimeZone(TimeZone.getTimeZone(Constants.TIMEZONE_UTC)); Date parsedTime = dateFormat.parse(jsonString); return today.plus(parsedTime.getTime()).toDate(); }