/** * @see groovy.time.BaseDuration#toMilliseconds() * * Change the duration into milliseconds, relative to 'now.' Therefore * things like timezone and time of year will affect how this conversion * occurs. */ public long toMilliseconds() { final Date now = new Date(); return TimeCategory.minus(plus(now), now).toMilliseconds(); }
public Duration minus(final Duration rhs) { return new TimeDuration(this.getDays() - rhs.getDays(), this.getHours() - rhs.getHours(), this.getMinutes() - rhs.getMinutes(), this.getSeconds() - rhs.getSeconds(), this.getMillis() - rhs.getMillis()); }
public DatumDependentDuration plus(final TimeDuration rhs) { return rhs.plus(this); }
public Date getAgo() { final Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -this.getDays()); cal.add(Calendar.HOUR_OF_DAY, -this.getHours()); cal.add(Calendar.MINUTE, -this.getMinutes()); cal.add(Calendar.SECOND, -this.getSeconds()); cal.add(Calendar.MILLISECOND, -this.getMillis()); return cal.getTime(); }
public static TimeDuration getMilliseconds(final Integer self) { return new TimeDuration(0, 0, 0, 0, self); }
public static TimeDuration getSeconds(final Integer self) { return new TimeDuration(0, 0, 0, self, 0); }
public Date getNow() { final Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, TimeDuration.this.getDays()); cal.add(Calendar.HOUR_OF_DAY, TimeDuration.this.getHours()); cal.add(Calendar.MINUTE, TimeDuration.this.getMinutes()); cal.add(Calendar.SECOND, TimeDuration.this.getSeconds()); cal.add(Calendar.MILLISECOND, TimeDuration.this.getMillis()); return cal.getTime(); } };
public static TimeDuration getMinutes(final Integer self) { return new TimeDuration(0, 0, self, 0, 0); }
@Override public Long apply(final TimeDuration input) { log.warn("deprecated automatic coercion of TimeDuration to Long (set breakpoint in TypeCoercions to inspect, use Duration instead of Long!)"); return input.toMilliseconds(); } });
public Duration plus(final TimeDuration rhs) { return rhs.plus(this); }
public static TimeDuration getHours(final Integer self) { return new TimeDuration(0, self, 0, 0, 0); }
@Override public Long apply(final TimeDuration input) { log.warn("deprecated automatic coercion of TimeDuration to Long (set breakpoint in TypeCoercions to inspect, use Duration instead of Long!)"); return input.toMilliseconds(); } });
public Duration plus(final TimeDuration rhs) { return rhs.plus(this); }
public Duration plus(final Duration rhs) { return new TimeDuration(this.getDays() + rhs.getDays(), this.getHours() + rhs.getHours(), this.getMinutes() + rhs.getMinutes(), this.getSeconds() + rhs.getSeconds(), this.getMillis() + rhs.getMillis()); }
/** * Subtract one date from the other. * * @param lhs a Date * @param rhs another Date * @return a Duration */ public static TimeDuration minus(final Date lhs, final Date rhs) { long milliseconds = lhs.getTime() - rhs.getTime(); long days = milliseconds / (24 * 60 * 60 * 1000); milliseconds -= days * 24 * 60 * 60 * 1000; int hours = (int) (milliseconds / (60 * 60 * 1000)); milliseconds -= hours * 60 * 60 * 1000; int minutes = (int) (milliseconds / (60 * 1000)); milliseconds -= minutes * 60 * 1000; int seconds = (int) (milliseconds / 1000); milliseconds -= seconds * 1000; return new TimeDuration((int) days, hours, minutes, seconds, (int) milliseconds); }
private static long getTimeoutMs(Map flags) { long timeout = TIMEOUT; Object tf = flags.get("timeout"); if (tf instanceof Number) { timeout = ((Number) tf).longValue(); } else if (tf instanceof TimeDuration) { timeout = ((TimeDuration) tf).toMilliseconds(); } //if (tf != null) timeout = tf; return timeout; }
public Duration plus(final TimeDuration rhs) { return rhs.plus(this); }
public TimeDuration minus(final TimeDuration rhs) { return new TimeDuration(this.getDays() - rhs.getDays(), this.getHours() - rhs.getHours(), this.getMinutes() - rhs.getMinutes(), this.getSeconds() - rhs.getSeconds(), this.getMillis() - rhs.getMillis()); }
/** * Get the DST offset (if any) for the default locale and the given date. * * @param self a Date * @return the DST offset as a Duration. */ public static Duration getDaylightSavingsOffset(Date self) { TimeZone timeZone = getTimeZone(self); int millis = (timeZone.useDaylightTime() && timeZone.inDaylightTime(self)) ? timeZone.getDSTSavings() : 0; return new TimeDuration(0, 0, 0, millis); }
/** * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated public void assertMBeanExistsEventually(ObjectName objectName, TimeDuration timeout) { assertMBeanExistsEventually(objectName, timeout.toMilliseconds(), TimeUnit.MILLISECONDS); }