@Override public Temporal apply(Temporal arg1, Temporal arg2, int flags) { if (arg1 == null) { return new RelativeTime(OFFSET_EXACT, arg2); } if (arg1 instanceof Time && arg2 instanceof Duration) { return ((Time) arg1).offset((Duration) arg2, flags); } else if (arg1 instanceof Range && arg2 instanceof Duration) { return ((Range) arg1).offset((Duration) arg2, flags); } else { throw new UnsupportedOperationException("OFFSET_EXACT not implemented for arg1=" + arg1.getClass() + ", arg2=" + arg2.getClass()); } } };
@Override public Temporal apply(Temporal arg1, Temporal arg2, int flags) { if (arg1 == null) { return new RelativeTime(OFFSET, arg2); } if (arg1 instanceof Time && arg2 instanceof Duration) { return ((Time) arg1).offset((Duration) arg2, flags | RELATIVE_OFFSET_INEXACT); } else if (arg1 instanceof Range && arg2 instanceof Duration) { return ((Range) arg1).offset((Duration) arg2, flags | RELATIVE_OFFSET_INEXACT); } else { throw new UnsupportedOperationException("OFFSET not implemented for arg1=" + arg1.getClass() + ", arg2=" + arg2.getClass()); } } },
@Override public Temporal apply(Temporal arg1, Temporal arg2, int flags) { if (arg1 == null) { return new RelativeTime(THIS, arg2, flags); } if (arg1 instanceof Time) { if (arg2 instanceof Duration) { return ((Duration) arg2).toTime((Time) arg1, flags); } else { // TODO: flags? return arg2.resolve((Time) arg1, flags | RESOLVE_TO_THIS); } } else { throw new UnsupportedOperationException("THIS not implemented for arg1=" + arg1.getClass() + ", arg2=" + arg2.getClass()); } } },
@Override public Time add(Duration offset) { Time t; Duration d = offset; if (this.tempOp == null) { t = new RelativeTime(base, d); t.approx = this.approx; t.mod = this.mod; } else if (this.tempOp == TemporalOp.OFFSET) { d = ((Duration) this.tempArg).add(offset); t = new RelativeTime(base, d); t.approx = this.approx; t.mod = this.mod; } else { t = new RelativeTime(this, d); } return t; }
@Override public Temporal intersect(Temporal t) { if (t == null) return this; if (t == TIME_UNKNOWN || t == DURATION_UNKNOWN) return this; if (t instanceof Time) { return intersect((Time) t); } else if (t instanceof Range) { return t.intersect(this); } else if (t instanceof Duration) { return new RelativeTime(this, TemporalOp.INTERSECT, t); } return null; }
@Override public Temporal intersect(Temporal t) { if (t instanceof Time) { return new RelativeTime((Time) t, TemporalOp.INTERSECT, this); } else if (t instanceof Range) { Range rt = (Range) t; // Assume begin/end defined (TODO: handle if duration defined) Time b = Time.max(begin, rt.begin); Time e = Time.min(end, rt.end); return new Range(b, e); } else if (t instanceof Duration) { return new InexactTime(null, (Duration) t, this); } return null; }
@Override public Time add(Duration offset) { return new RelativeTime(this, TemporalOp.OFFSET_EXACT, offset); }
@Override public Temporal intersect(Temporal t) { return new RelativeTime(this, TemporalOp.INTERSECT, t); }
public Temporal prev() { Duration per = getPeriod(); if (per != null) { if (this instanceof Duration) { return new RelativeTime(new RelativeTime(TemporalOp.THIS, this, DUR_RESOLVE_FROM_AS_REF), TemporalOp.OFFSET, per.multiplyBy(-1)); } else { // return new RelativeTime(new RelativeTime(TemporalOp.THIS, this), // TemporalOp.OFFSET, per.multiplyBy(-1)); return TemporalOp.OFFSET.apply(this, per.multiplyBy(-1)); } } return null; }
public Temporal next() { Duration per = getPeriod(); if (per != null) { if (this instanceof Duration) { return new RelativeTime(new RelativeTime(TemporalOp.THIS, this, DUR_RESOLVE_TO_AS_REF), TemporalOp.OFFSET, per); } else { // return new RelativeTime(new RelativeTime(TemporalOp.THIS, this), // TemporalOp.OFFSET, per); return TemporalOp.OFFSET.apply(this, per); } } return null; }
@Override public Time add(Duration offset) { // TODO: Check logic // if (getTimeLabel() != null) { if (getStandardTemporalType() != null) { // Time has some meaning, keep as is return new RelativeTime(this, TemporalOp.OFFSET_EXACT, offset); } else return new TimeWithRange(this, range.offset(offset,0)); }
@Override public Time add(Duration offset) { Time t = new RelativeTime(this, TemporalOp.OFFSET_EXACT, offset); // t.approx = this.approx; // t.mod = this.mod; return t; }
@Override public Time add(Duration offset) { //if (getTimeLabel() != null) { if (getStandardTemporalType() != null) { // Time has some meaning, keep as is return new RelativeTime(this, TemporalOp.OFFSET_EXACT, offset); } else { // Some other time, who know what it means // Try to do offset return new InexactTime(this, (Time) TemporalOp.OFFSET_EXACT.apply(base, offset), duration, (Range) TemporalOp.OFFSET_EXACT.apply(range, offset)); } }
@Override public Time offset(Duration offset, int offsetFlags) { if ((offsetFlags & RELATIVE_OFFSET_INEXACT) != 0) { return new RelativeTime(this, TemporalOp.OFFSET, offset); } else { return new RelativeTime(this, TemporalOp.OFFSET_EXACT, offset); } }
@Override public Time add(Duration offset) { return new RelativeTime(this, TemporalOp.OFFSET_EXACT, offset); }
@Override public SUTime.Time add(SUTime.Duration offset) { return new SUTime.RelativeTime(this, SUTime.TemporalOp.OFFSET_EXACT, offset); } }
@Override public Time intersect(Time t) { if (base == TIME_REF || base == null) { if (t instanceof PartialTime && tempOp == TemporalOp.OFFSET) { RelativeTime rt = new RelativeTime(this, tempOp, tempArg); rt.base = t; return rt; } } return new RelativeTime(this, TemporalOp.INTERSECT, t); }
@Override public SUTime.Temporal prev() { // TODO: Handle holidays that are not yearly return new SUTime.RelativeTime( new SUTime.RelativeTime(SUTime.TemporalOp.PREV, SUTime.YEAR, SUTime.RESOLVE_TO_PAST), SUTime.TemporalOp.INTERSECT, this); }
@Override public SUTime.Temporal next() { // TODO: Handle holidays that are not yearly return new SUTime.RelativeTime( new SUTime.RelativeTime(SUTime.TemporalOp.NEXT, SUTime.YEAR, SUTime.RESOLVE_TO_FUTURE), SUTime.TemporalOp.INTERSECT, this); }
@Override public Time intersect(Time t) { if (base instanceof PartialTime && t instanceof PartialTime) { return new OrdinalTime(base.intersect(t), n); } else { return new RelativeTime(t, TemporalOp.INTERSECT, this); } }