public Time intersect(Time t) { if (t == null || t == TIME_UNKNOWN) return this; if (base == null) return t; if (t instanceof CompositePartialTime) { return t.intersect(this); } else if (t instanceof PartialTime) { if (!isCompatible((PartialTime) t)) { return null; } Partial p = JodaTimeUtils.combine(base, ((PartialTime) t).base); return new PartialTime(p); } else if (t instanceof GroundedTime) { return t.intersect(this); } else if (t instanceof RelativeTime) { return t.intersect(this); } else { Time cpt = makeComposite(this, t); if (cpt != null) { return cpt; } if (t instanceof InexactTime) { return t.intersect(this); } } return null; // return new RelativeTime(this, TemporalOp.INTERSECT, t); }
public static Pair<PartialTime, PartialTime> getCompatible(PartialTime t1, PartialTime t2) { // Incompatible timezones if (t1.dateTimeZone != null && t2.dateTimeZone != null && !t1.dateTimeZone.equals(t2.dateTimeZone)) return null; if (t1.isCompatible(t2)) return Pair.makePair(t1,t2); if (t1.uncertaintyGranularity != null && t2.uncertaintyGranularity == null) { if (t1.uncertaintyGranularity.compareTo(t2.getDuration()) > 0) { // Drop the uncertain fields from t1 Duration d = t1.uncertaintyGranularity; PartialTime t1b = t1.reduceGranularityTo(d); if (t1b.isCompatible(t2)) return Pair.makePair(t1b,t2); } } else if (t1.uncertaintyGranularity == null && t2.uncertaintyGranularity != null) { if (t2.uncertaintyGranularity.compareTo(t1.getDuration()) > 0) { // Drop the uncertain fields from t2 Duration d = t2.uncertaintyGranularity; PartialTime t2b = t2.reduceGranularityTo(d); if (t1.isCompatible(t2b)) return Pair.makePair(t1,t2b); } } else if (t1.uncertaintyGranularity != null && t2.uncertaintyGranularity != null) { Duration d1 = Duration.max(t1.uncertaintyGranularity, t2.getDuration()); Duration d2 = Duration.max(t2.uncertaintyGranularity, t1.getDuration()); PartialTime t1b = t1.reduceGranularityTo(d1); PartialTime t2b = t2.reduceGranularityTo(d2); if (t1b.isCompatible(t2b)) return Pair.makePair(t1b,t2b); } return null; }
public static Pair<PartialTime, PartialTime> getCompatible(PartialTime t1, PartialTime t2) { // Incompatible timezones if (t1.dateTimeZone != null && t2.dateTimeZone != null && !t1.dateTimeZone.equals(t2.dateTimeZone)) return null; if (t1.isCompatible(t2)) return Pair.makePair(t1,t2); if (t1.uncertaintyGranularity != null && t2.uncertaintyGranularity == null) { if (t1.uncertaintyGranularity.compareTo(t2.getDuration()) > 0) { // Drop the uncertain fields from t1 Duration d = t1.uncertaintyGranularity; PartialTime t1b = t1.reduceGranularityTo(d); if (t1b.isCompatible(t2)) return Pair.makePair(t1b,t2); } } else if (t1.uncertaintyGranularity == null && t2.uncertaintyGranularity != null) { if (t2.uncertaintyGranularity.compareTo(t1.getDuration()) > 0) { // Drop the uncertain fields from t2 Duration d = t2.uncertaintyGranularity; PartialTime t2b = t2.reduceGranularityTo(d); if (t1.isCompatible(t2b)) return Pair.makePair(t1,t2b); } } else if (t1.uncertaintyGranularity != null && t2.uncertaintyGranularity != null) { Duration d1 = Duration.max(t1.uncertaintyGranularity, t2.getDuration()); Duration d2 = Duration.max(t2.uncertaintyGranularity, t1.getDuration()); PartialTime t1b = t1.reduceGranularityTo(d1); PartialTime t2b = t2.reduceGranularityTo(d2); if (t1b.isCompatible(t2b)) return Pair.makePair(t1b,t2b); } return null; }
public static Pair<PartialTime, PartialTime> getCompatible(PartialTime t1, PartialTime t2) { // Incompatible timezones if (t1.dateTimeZone != null && t2.dateTimeZone != null && !t1.dateTimeZone.equals(t2.dateTimeZone)) return null; if (t1.isCompatible(t2)) return Pair.makePair(t1,t2); if (t1.uncertaintyGranularity != null && t2.uncertaintyGranularity == null) { if (t1.uncertaintyGranularity.compareTo(t2.getDuration()) > 0) { // Drop the uncertain fields from t1 Duration d = t1.uncertaintyGranularity; PartialTime t1b = t1.reduceGranularityTo(d); if (t1b.isCompatible(t2)) return Pair.makePair(t1b,t2); } } else if (t1.uncertaintyGranularity == null && t2.uncertaintyGranularity != null) { if (t2.uncertaintyGranularity.compareTo(t1.getDuration()) > 0) { // Drop the uncertain fields from t2 Duration d = t2.uncertaintyGranularity; PartialTime t2b = t2.reduceGranularityTo(d); if (t1.isCompatible(t2b)) return Pair.makePair(t1,t2b); } } else if (t1.uncertaintyGranularity != null && t2.uncertaintyGranularity != null) { Duration d1 = Duration.max(t1.uncertaintyGranularity, t2.getDuration()); Duration d2 = Duration.max(t2.uncertaintyGranularity, t1.getDuration()); PartialTime t1b = t1.reduceGranularityTo(d1); PartialTime t2b = t2.reduceGranularityTo(d2); if (t1b.isCompatible(t2b)) return Pair.makePair(t1b,t2b); } return null; }