Partial partialRef = ref.getJodaTimePartial(); if (partialRef == null) { throw new UnsupportedOperationException("Cannot resolve if reftime is of class: " + ref.getClass()); Duration resolvedGranularity = resolved.getGranularity(); Duration refGranularity = ref.getGranularity(); if (resolved.compareTo(ref) > 0) { Time t = (Time) this.prev(); if (t != null) { resolved = (Time) t.resolve(ref, 0); if (resolved.compareTo(ref) < 0) { Time t = (Time) this.next(); if (t != null) { resolved = (Time) t.resolve(ref, 0); if (resolved.compareTo(ref) > 0) { Time t = (Time) this.prev(); if (t != null) { Time resolved2 = (Time) t.resolve(ref, 0); resolved = Time.closest(ref, resolved, resolved2); } if (resolved.compareTo(ref) < 0) { Time t = (Time) this.next(); if (t != null) { Time resolved2 = (Time) t.resolve(ref, 0); resolved = Time.closest(ref, resolved, resolved2);
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; }
Partial partialRef = ref.getJodaTimePartial(); if (partialRef == null) { throw new UnsupportedOperationException("Cannot resolve if reftime is of class: " + ref.getClass()); Duration resolvedGranularity = resolved.getGranularity(); Duration refGranularity = ref.getGranularity(); if (resolved.compareTo(ref) > 0) { Time t = (Time) this.prev(); if (t != null) { resolved = (Time) t.resolve(ref, 0); if (resolved.compareTo(ref) < 0) { Time t = (Time) this.next(); if (t != null) { resolved = (Time) t.resolve(ref, 0); if (resolved.compareTo(ref) > 0) { Time t = (Time) this.prev(); if (t != null) { Time resolved2 = (Time) t.resolve(ref, 0); resolved = Time.closest(ref, resolved, resolved2); } if (resolved.compareTo(ref) < 0) { Time t = (Time) this.next(); if (t != null) { Time resolved2 = (Time) t.resolve(ref, 0); resolved = Time.closest(ref, resolved, resolved2);
Partial partialRef = ref.getJodaTimePartial(); if (partialRef == null) { throw new UnsupportedOperationException("Cannot resolve if reftime is of class: " + ref.getClass()); Duration resolvedGranularity = resolved.getGranularity(); Duration refGranularity = ref.getGranularity(); if (resolved.compareTo(ref) > 0) { Time t = (Time) this.prev(); if (t != null) { resolved = (Time) t.resolve(ref, 0); if (resolved.compareTo(ref) < 0) { Time t = (Time) this.next(); if (t != null) { resolved = (Time) t.resolve(ref, 0); if (resolved.compareTo(ref) > 0) { Time t = (Time) this.prev(); if (t != null) { Time resolved2 = (Time) t.resolve(ref, 0); resolved = Time.closest(ref, resolved, resolved2); } if (resolved.compareTo(ref) < 0) { Time t = (Time) this.next(); if (t != null) { Time resolved2 = (Time) t.resolve(ref, 0); resolved = Time.closest(ref, resolved, resolved2);
@Override public Duration getDuration() { /* TimeLabel tl = getTimeLabel(); if (tl != null) { return tl.getDuration(); } */ StandardTemporalType tlt = getStandardTemporalType(); if (tlt != null) { return tlt.getDuration(); } Duration bd = (base != null) ? Duration.getDuration(JodaTimeUtils.getJodaTimePeriod(base)) : null; if (tod != null) { Duration d = tod.getDuration(); return (bd.compareTo(d) < 0) ? bd : d; } if (dow != null) { Duration d = dow.getDuration(); return (bd.compareTo(d) < 0) ? bd : d; } if (poy != null) { Duration d = poy.getDuration(); return (bd.compareTo(d) < 0) ? bd : d; } return bd; }
public Duration getDuration() { TimeLabel tl = getTimeLabel(); if (tl != null) { return tl.getDuration(); } TimeLabelType tlt = getTimeLabelType(); if (tlt != null) { return tlt.getDuration(); } Duration bd = (base != null) ? Duration.getDuration(JodaTimeUtils.getJodaTimePeriod(base)) : null; if (tod != null) { Duration d = tod.getDuration(); return (bd.compareTo(d) < 0) ? bd : d; } if (dow != null) { Duration d = dow.getDuration(); return (bd.compareTo(d) < 0) ? bd : d; } if (poy != null) { Duration d = poy.getDuration(); return (bd.compareTo(d) < 0) ? bd : d; } return bd; }
public Duration getDuration() { /* TimeLabel tl = getTimeLabel(); if (tl != null) { return tl.getDuration(); } */ StandardTemporalType tlt = getStandardTemporalType(); if (tlt != null) { return tlt.getDuration(); } Duration bd = (base != null) ? Duration.getDuration(JodaTimeUtils.getJodaTimePeriod(base)) : null; if (tod != null) { Duration d = tod.getDuration(); return (bd.compareTo(d) < 0) ? bd : d; } if (dow != null) { Duration d = dow.getDuration(); return (bd.compareTo(d) < 0) ? bd : d; } if (poy != null) { Duration d = poy.getDuration(); return (bd.compareTo(d) < 0) ? bd : d; } return bd; }
public static Duration difference(Time t1, Time t2) { // 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; } }
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; } }
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; } }
private static SUTime.Time findReferenceDate(List<TimeExpression> timeExpressions) { // Find first full date in this annotation with year, month, and day for (TimeExpression te:timeExpressions) { SUTime.Temporal t = te.getTemporal(); if (t instanceof SUTime.Time) { if (t.isGrounded()) { return t.getTime(); } else if (t instanceof SUTime.PartialTime) { if (JodaTimeUtils.hasYYYYMMDD(t.getTime().getJodaTimePartial())) { return t.getTime(); } else if (JodaTimeUtils.hasYYMMDD(t.getTime().getJodaTimePartial())) { return t.getTime().resolve(SUTime.getCurrentTime()).getTime(); } } } } return null; }
public Time subtract(Duration offset) { return add(offset.multiplyBy(-1)); }
public Time mid() { if (duration != null && begin != null) { Time b = begin.getRange(RANGE_FLAGS_PAD_SPECIFIED,duration.getGranularity()).begin(); return b.add(duration.divideBy(2)); } else if (duration != null && end != null) { return end.subtract(duration.divideBy(2)); } else if (begin != null && end != null) { // TODO: .... } else if (begin != null) { return begin; } else if (end != null) { return end; } return null; }
public Time subtract(Duration offset) { return add(offset.multiplyBy(-1)); }
public Time mid() { if (duration != null && begin != null) { Time b = begin.getRange(RANGE_FLAGS_PAD_SPECIFIED,duration.getGranularity()).begin(); return b.add(duration.divideBy(2)); } else if (duration != null && end != null) { return end.subtract(duration.divideBy(2)); } else if (begin != null && end != null) { // TODO: .... } else if (begin != null) { return begin; } else if (end != null) { return end; } return null; }
public Time mid() { if (duration != null && begin != null) { return begin.add(duration.divideBy(2)); } else if (duration != null && end != null) { return end.subtract(duration.divideBy(2)); } else if (begin != null && end != null) { // TODO: .... } else if (begin != null) { return begin; } else if (end != null) { return end; } return null; }