public static Time closest(Time ref, Time... times) { Time res = null; long refMillis = ref.getJodaTimeInstant().getMillis(); long min = 0; for (Time t:times) { long d = Math.abs(refMillis - t.getJodaTimeInstant().getMillis()); if (res == null || d < min) { res = t; min = d; } } return res; }
public Instant getJodaTimeInstant() { Instant p = null; if (base != null) { p = base.getJodaTimeInstant(); } if (p == null && range != null) { p = range.mid().getJodaTimeInstant(); } return p; }
public boolean isComparable(Time t) { Instant i = this.getJodaTimeInstant(); Instant i2 = t.getJodaTimeInstant(); return (i != null && i2 != null); }
public Duration resolve(Time refTime, int flags) { Instant instant = (refTime != null) ? refTime.getJodaTimeInstant() : null; if (instant != null) { if ((flags & DUR_RESOLVE_FROM_AS_REF) != 0) { return new DurationWithMillis(this, period.toPeriod().toDurationFrom(instant)); } else if ((flags & DUR_RESOLVE_TO_AS_REF) != 0) { return new DurationWithMillis(this, period.toPeriod().toDurationTo(instant)); } } return this; }
public boolean isComparable(Time t) { Instant i = this.getJodaTimeInstant(); Instant i2 = t.getJodaTimeInstant(); return (i != null && i2 != null); }
@Override public int compareTo(Time t) { Instant i = this.getJodaTimeInstant(); Instant i2 = t.getJodaTimeInstant(); return i.compareTo(i2); }
@Override public Duration resolve(Time refTime, int flags) { Instant instant = (refTime != null) ? refTime.getJodaTimeInstant() : null; if (instant != null) { if ((flags & DUR_RESOLVE_FROM_AS_REF) != 0) { return new DurationWithMillis(this, period.toPeriod().toDurationFrom(instant)); } else if ((flags & DUR_RESOLVE_TO_AS_REF) != 0) { return new DurationWithMillis(this, period.toPeriod().toDurationTo(instant)); } } return this; }
@Override public Instant getJodaTimeInstant() { Instant p = null; if (base != null) { p = base.getJodaTimeInstant(); } if (p == null && range != null) { p = range.mid().getJodaTimeInstant(); } return p; }
/** * Checks if the provided time is within the current range. * @param t A time to check containment for * @return Returns whether the provided time is within the current range */ public boolean contains(Time t) { return this.getJodaTimeInterval().contains(t.getJodaTimeInstant()); }
@Override public boolean isComparable(Time t) { Instant i = this.getJodaTimeInstant(); Instant i2 = t.getJodaTimeInstant(); return (i != null && i2 != null); }
public org.joda.time.Interval getJodaTimeInterval() { return new org.joda.time.Interval(begin.getJodaTimeInstant(), end.getJodaTimeInstant()); }
Instant instant = refTime.getJodaTimeInstant(); if (instant != null) { for (DateTimeFieldType dtft : dtFieldTypes) {
public static Duration difference(Time t1, Time t2) { // TODO: Difference does not work between days of the week // Get duration from this t1 to t2 if (t1 == null || t2 == null) return null; Instant i1 = t1.getJodaTimeInstant(); Instant i2 = t2.getJodaTimeInstant(); if (i1 == null || i2 == null) return null; Duration d = new DurationWithMillis(i2.getMillis() - i1.getMillis()); Duration g1 = t1.getGranularity(); Duration g2 = t2.getGranularity(); Duration g = Duration.max(g1, g2); if (g != null) { Period p = g.getJodaTimePeriod(); p = p.normalizedStandard(); Period p2 = JodaTimeUtils.discardMoreSpecificFields(d.getJodaTimePeriod(), p.getFieldType(p.size() - 1), i1.getChronology()); return new DurationWithFields(p2); } else { return d; } }
/** * Checks if the provided range r is within the current range. * Note that equal ranges also returns true. * * @param r range * @return true if range r is contained in r */ public boolean contains(Range r) { if ((this.beginTime().getJodaTimeInstant().isBefore(r.beginTime().getJodaTimeInstant()) || this.beginTime().getJodaTimeInstant().isEqual(r.beginTime().getJodaTimeInstant())) && (this.endTime().getJodaTimeInstant().isAfter(r.endTime().getJodaTimeInstant()) || this.endTime().getJodaTimeInstant().isEqual(r.endTime().getJodaTimeInstant()))) { return true; } return false; }
public org.joda.time.Interval getJodaTimeInterval() { return new org.joda.time.Interval(begin.getJodaTimeInstant(), end.getJodaTimeInstant()); }
@Override public Instant getJodaTimeInstant() { Instant p = null; if (base != null) { p = base.getJodaTimeInstant(); } if (p == null && range != null) { p = range.mid().getJodaTimeInstant(); } return p; }
/** * Checks if the provided time is within the current range. * @param t A time to check containment for * @return Returns whether the provided time is within the current range */ public boolean contains(Time t) { return this.getJodaTimeInterval().contains(t.getJodaTimeInstant()); }
@Override public Duration resolve(Time refTime, int flags) { Instant instant = (refTime != null) ? refTime.getJodaTimeInstant() : null; if (instant != null) { if ((flags & DUR_RESOLVE_FROM_AS_REF) != 0) { return new DurationWithMillis(this, period.toPeriod().toDurationFrom(instant)); } else if ((flags & DUR_RESOLVE_TO_AS_REF) != 0) { return new DurationWithMillis(this, period.toPeriod().toDurationTo(instant)); } } return this; }
@Override public int compareTo(Time t) { Instant i = this.getJodaTimeInstant(); Instant i2 = t.getJodaTimeInstant(); return i.compareTo(i2); }
@Override public boolean isComparable(Time t) { Instant i = this.getJodaTimeInstant(); Instant i2 = t.getJodaTimeInstant(); return (i != null && i2 != null); }