@Override public PartialTime reduceGranularityTo(Duration granularity) { Partial p = JodaTimeUtils.discardMoreSpecificFields( base, JodaTimeUtils.getMostSpecific(granularity.getJodaTimePeriod()) ); return new CompositePartialTime(this, p, poy.reduceGranularityTo(granularity), dow.reduceGranularityTo(granularity), tod.reduceGranularityTo(granularity)); }
@Override public PartialTime reduceGranularityTo(Duration granularity) { Partial pbase = base; if (JodaTimeUtils.hasField(granularity.getJodaTimePeriod(), DurationFieldType.weeks())) { // Make sure the partial time has weeks in it if (!JodaTimeUtils.hasField(pbase, DateTimeFieldType.weekOfWeekyear())) { // Add week year to it pbase = JodaTimeUtils.resolveWeek(pbase); } } Partial p = JodaTimeUtils.discardMoreSpecificFields( pbase, JodaTimeUtils.getMostSpecific(granularity.getJodaTimePeriod()) ); return new PartialTime(this,p); }
public static Partial resolveDowToDay(Partial p) { if (p.isSupported(DateTimeFieldType.dayOfWeek())) { if (!p.isSupported(DateTimeFieldType.dayOfMonth())) { if (p.isSupported(DateTimeFieldType.weekOfWeekyear()) && (p.isSupported(DateTimeFieldType.year()))) { // Convert from year to weekyear (to avoid weirdness when the weekyear and year don't match at the beginning of the year) Partial pwy = withWeekYear(p); Instant t2 = getInstant(pwy); DateTime t1 = pwy.toDateTime(t2); Partial res = getPartial(t1.toInstant(), EMPTY_ISO_PARTIAL); DateTimeFieldType mostSpecific = getMostSpecific(p); res = discardMoreSpecificFields(res, mostSpecific.getDurationType()); return res; } } } return p; }
for (DateTimeFieldType dtft : dtFieldTypes) { if (p.isSupported(dtft)) { t = new PartialTime(JodaTimeUtils.discardMoreSpecificFields(p, dtft)); if (instant.isSupported(dtft)) { Partial p2 = JodaTimeUtils.getPartial(instant, p.with(dtft, 1)); t = new PartialTime(JodaTimeUtils.discardMoreSpecificFields(p2, dtft));
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 Partial resolveDowToDay(Partial p1, Partial p2) { // Discard anything that's more specific than dayOfMonth for p2 p2 = JodaTimeUtils.discardMoreSpecificFields(p2, DateTimeFieldType.dayOfMonth()); if (isCompatible(p1,p2)) { if (p1.isSupported(DateTimeFieldType.dayOfWeek())) { if (!p1.isSupported(DateTimeFieldType.dayOfMonth())) { if (p2.isSupported(DateTimeFieldType.dayOfMonth()) && p2.isSupported(DateTimeFieldType.monthOfYear()) && p2.isSupported(DateTimeFieldType.year())) { Instant t2 = getInstant(p2); DateTime t1 = p1.toDateTime(t2); return getPartial(t1.toInstant(), p1.with(DateTimeFieldType.dayOfMonth(), 1)/*.with(DateTimeFieldType.weekOfWeekyear(), 1) */); } } } } return p1; }
p = discardMoreSpecificFields(p, mostSpecific);
public PartialTime reduceGranularityTo(Duration granularity) { Partial p = JodaTimeUtils.discardMoreSpecificFields( base, JodaTimeUtils.getMostSpecific(granularity.getJodaTimePeriod()) ); return new CompositePartialTime(this, p, poy.reduceGranularityTo(granularity), dow.reduceGranularityTo(granularity), tod.reduceGranularityTo(granularity)); }
@Override public PartialTime reduceGranularityTo(Duration granularity) { Partial p = JodaTimeUtils.discardMoreSpecificFields( base, JodaTimeUtils.getMostSpecific(granularity.getJodaTimePeriod()) ); return new CompositePartialTime(this, p, poy.reduceGranularityTo(granularity), dow.reduceGranularityTo(granularity), tod.reduceGranularityTo(granularity)); }
public PartialTime reduceGranularityTo(Duration granularity) { Partial pbase = base; if (JodaTimeUtils.hasField(granularity.getJodaTimePeriod(), DurationFieldType.weeks())) { // Make sure the partial time has weeks in it if (!JodaTimeUtils.hasField(pbase, DateTimeFieldType.weekOfWeekyear())) { // Add week year to it pbase = JodaTimeUtils.resolveWeek(pbase); } } Partial p = JodaTimeUtils.discardMoreSpecificFields( pbase, JodaTimeUtils.getMostSpecific(granularity.getJodaTimePeriod()) ); return new PartialTime(this,p); }
@Override public PartialTime reduceGranularityTo(Duration granularity) { Partial pbase = base; if (JodaTimeUtils.hasField(granularity.getJodaTimePeriod(), DurationFieldType.weeks())) { // Make sure the partial time has weeks in it if (!JodaTimeUtils.hasField(pbase, DateTimeFieldType.weekOfWeekyear())) { // Add week year to it pbase = JodaTimeUtils.resolveWeek(pbase); } } Partial p = JodaTimeUtils.discardMoreSpecificFields( pbase, JodaTimeUtils.getMostSpecific(granularity.getJodaTimePeriod()) ); return new PartialTime(this,p); }
public static Partial resolveDowToDay(Partial p) { if (p.isSupported(DateTimeFieldType.dayOfWeek())) { if (!p.isSupported(DateTimeFieldType.dayOfMonth())) { if (p.isSupported(DateTimeFieldType.weekOfWeekyear()) && p.isSupported(DateTimeFieldType.year())) { Instant t2 = getInstant(p); DateTime t1 = p.toDateTime(t2); Partial res = getPartial(t1.toInstant(), EMPTY_ISO_PARTIAL); DateTimeFieldType mostSpecific = getMostSpecific(p); res = discardMoreSpecificFields(res, mostSpecific.getDurationType()); return res; } } } return p; } // Uses p2 to resolve week for p1
public static Partial resolveDowToDay(Partial p) { if (p.isSupported(DateTimeFieldType.dayOfWeek())) { if (!p.isSupported(DateTimeFieldType.dayOfMonth())) { if (p.isSupported(DateTimeFieldType.weekOfWeekyear()) && p.isSupported(DateTimeFieldType.year())) { Instant t2 = getInstant(p); DateTime t1 = p.toDateTime(t2); Partial res = getPartial(t1.toInstant(), EMPTY_ISO_PARTIAL); DateTimeFieldType mostSpecific = getMostSpecific(p); res = discardMoreSpecificFields(res, mostSpecific.getDurationType()); return res; } } } return p; } // Uses p2 to resolve week for p1
public static Partial resolveDowToDay(Partial p) { if (p.isSupported(DateTimeFieldType.dayOfWeek())) { if (!p.isSupported(DateTimeFieldType.dayOfMonth())) { if (p.isSupported(DateTimeFieldType.weekOfWeekyear()) && (p.isSupported(DateTimeFieldType.year()))) { // Convert from year to weekyear (to avoid weirdness when the weekyear and year don't match at the beginning of the year) Partial pwy = withWeekYear(p); Instant t2 = getInstant(pwy); DateTime t1 = pwy.toDateTime(t2); Partial res = getPartial(t1.toInstant(), EMPTY_ISO_PARTIAL); DateTimeFieldType mostSpecific = getMostSpecific(p); res = discardMoreSpecificFields(res, mostSpecific.getDurationType()); return res; } } } return p; }
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) { // 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 Partial resolveDowToDay(Partial p1, Partial p2) { // Discard anything that's more specific than dayOfMonth for p2 p2 = JodaTimeUtils.discardMoreSpecificFields(p2, DateTimeFieldType.dayOfMonth()); if (isCompatible(p1,p2)) { if (p1.isSupported(DateTimeFieldType.dayOfWeek())) { if (!p1.isSupported(DateTimeFieldType.dayOfMonth())) { if (p2.isSupported(DateTimeFieldType.dayOfMonth()) && p2.isSupported(DateTimeFieldType.monthOfYear()) && p2.isSupported(DateTimeFieldType.year())) { Instant t2 = getInstant(p2); DateTime t1 = p1.toDateTime(t2); return getPartial(t1.toInstant(), p1.with(DateTimeFieldType.dayOfMonth(), 1)/*.with(DateTimeFieldType.weekOfWeekyear(), 1) */); } } } } return p1; }
public static Partial resolveDowToDay(Partial p1, Partial p2) { // Discard anything that's more specific than dayOfMonth for p2 p2 = JodaTimeUtils.discardMoreSpecificFields(p2, DateTimeFieldType.dayOfMonth()); if (isCompatible(p1,p2)) { if (p1.isSupported(DateTimeFieldType.dayOfWeek())) { if (!p1.isSupported(DateTimeFieldType.dayOfMonth())) { if (p2.isSupported(DateTimeFieldType.dayOfMonth()) && p2.isSupported(DateTimeFieldType.monthOfYear()) && p2.isSupported(DateTimeFieldType.year())) { Instant t2 = getInstant(p2); DateTime t1 = p1.toDateTime(t2); return getPartial(t1.toInstant(), p1.with(DateTimeFieldType.dayOfMonth(), 1)/*.with(DateTimeFieldType.weekOfWeekyear(), 1) */); } } } } return p1; } // Resolve dow for p1
p = discardMoreSpecificFields(p, mostSpecific);