protected static Partial setField(Partial base, DateTimeFieldType field, int value) { if (base == null) { return new Partial(field, value); } else { return base.with(field, value); } }
public static Partial resolveWeek(Partial p1, Partial p2) { if (isCompatible(p1,p2)) { 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.without(DateTimeFieldType.dayOfMonth()).without(DateTimeFieldType.monthOfYear()).with(DateTimeFieldType.weekOfWeekyear(), 1)); } } } return p1; } public static Partial resolveWeek(Partial p)
public static Partial withWeekYear(Partial p) { Partial res = new Partial(); for (int i = 0; i < p.size(); i++) { DateTimeFieldType fieldType = p.getFieldType(i); if (fieldType == DateTimeFieldType.year()) { res = res.with(DateTimeFieldType.weekyear(), p.getValue(i)); } else { res = res.with(fieldType, p.getValue(i)); } } return res; }
p = p.without(JodaTimeUtils.DecadeOfCentury); p = p.without(DateTimeFieldType.centuryOfEra()); p = p.with(DateTimeFieldType.year(), year); } else { int year = p.get(JodaTimeUtils.DecadeOfCentury)*10; p = p.without(JodaTimeUtils.DecadeOfCentury); p = p.with(DateTimeFieldType.yearOfCentury(), year); int year = p.get(DateTimeFieldType.centuryOfEra()) * 100; p = p.without(DateTimeFieldType.centuryOfEra()); p = p.with(DateTimeFieldType.year(), year); if (p.isSupported(DateTimeFieldType.weekOfWeekyear())) { if (!p.isSupported(DateTimeFieldType.dayOfMonth()) && !p.isSupported(DateTimeFieldType.dayOfWeek())) { p = p.with(DateTimeFieldType.dayOfWeek(), 1); if (p.isSupported(DateTimeFieldType.monthOfYear())) { p = p.without(DateTimeFieldType.monthOfYear()); if (fieldType == DateTimeFieldType.monthOfYear()) { if (p.isSupported(QuarterOfYear)) { p = p.with(DateTimeFieldType.monthOfYear(), (p.get(QuarterOfYear)-1)*3+1); continue; } else if (p.isSupported(HalfYearOfYear)) { p = p.with(DateTimeFieldType.monthOfYear(), (p.get(HalfYearOfYear)-1)*6+1); continue; p = p.with(fieldType, p2.getValue(i));
public static Partial discardMoreSpecificFields(Partial p, DateTimeFieldType d) { Partial res = new Partial(); for (int i = 0; i < p.size(); i++) { DateTimeFieldType fieldType = p.getFieldType(i); if (fieldType.equals(d) || isMoreGeneral(fieldType, d, p.getChronology())) { res = res.with(fieldType, p.getValue(i)); } } if (res.isSupported(JodaTimeUtils.DecadeOfCentury) && !res.isSupported(DateTimeFieldType.centuryOfEra())) { if (p.isSupported(DateTimeFieldType.year())) { res = res.with(DateTimeFieldType.centuryOfEra(), p.get(DateTimeFieldType.year()) / 100); } } return res; }
p = p.with(DateTimeFieldType.year(), y2); century--; p = p.with(DateTimeFieldType.centuryOfEra(), century); p = p.with(fieldType, p2.getValue(i)); if (p.isSupported(DateTimeFieldType.yearOfCentury()) && p.isSupported(DateTimeFieldType.centuryOfEra())) { int year = p.get(DateTimeFieldType.yearOfCentury()) + p.get(DateTimeFieldType.centuryOfEra())*100; p = p.with(DateTimeFieldType.year(), year); p = p.without(DateTimeFieldType.yearOfCentury()); p = p.without(DateTimeFieldType.centuryOfEra());
public static Partial resolveWeek(Partial p) { // Figure out week if (p.isSupported(DateTimeFieldType.dayOfMonth()) && p.isSupported(DateTimeFieldType.monthOfYear()) && p.isSupported(DateTimeFieldType.year())) { Instant t = getInstant(p); // return getPartial(t.toInstant(), p.without(DateTimeFieldType.dayOfMonth()).without(DateTimeFieldType.monthOfYear()).with(DateTimeFieldType.weekOfWeekyear(), 1)); return getPartial(t.toInstant(), p.with(DateTimeFieldType.weekOfWeekyear(), 1)); } else return p; }
p = p.with(DateTimeFieldType.year(), y2); p = p.with(fieldType, p2.getValue(i)); if (p.isSupported(DateTimeFieldType.yearOfCentury()) && p.isSupported(DateTimeFieldType.centuryOfEra())) { int year = p.get(DateTimeFieldType.yearOfCentury()) + p.get(DateTimeFieldType.centuryOfEra())*100; p = p.with(DateTimeFieldType.year(), year); p = p.without(DateTimeFieldType.yearOfCentury()); p = p.without(DateTimeFieldType.centuryOfEra()); p = p.with(DateTimeFieldType.hourOfDay(), hour); } else { p = p.with(DateTimeFieldType.clockhourOfDay(), hour);
public static Partial discardMoreSpecificFields(Partial p, DurationFieldType dft) { DurationField df = dft.getField(p.getChronology()); Partial res = new Partial(); for (int i = 0; i < p.size(); i++) { DateTimeFieldType fieldType = p.getFieldType(i); DurationField f = fieldType.getDurationType().getField(p.getChronology()); int cmp = df.compareTo(f); if (cmp <= 0) { res = res.with(fieldType, p.getValue(i)); } } return res; }
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; }
for (DateTimeFieldType dtft : dtFieldTypes) { if (instant.isSupported(dtft)) { Partial p2 = JodaTimeUtils.getPartial(instant, p.with(dtft, 1)); t = new PartialTime(JodaTimeUtils.discardMoreSpecificFields(p2, dtft));
protected static Partial setField(Partial base, DateTimeFieldType field, int value) { if (base == null) { return new Partial(field, value); } else { return base.with(field, value); } }
protected static Partial setField(Partial base, DateTimeFieldType field, int value) { if (base == null) { return new Partial(field, value); } else { return base.with(field, value); } }
protected static Partial setField(Partial base, DateTimeFieldType field, int value) { if (base == null) { return new Partial(field, value); } else { return base.with(field, value); } }
public FlightSchedule(DateTime validFromInclusive, DateTime validUntilExclusive, int flightHourOfDay, int flightMinuteOfHour) { this.validFromInclusive = validFromInclusive; this.validUntilInclusive = validUntilExclusive; flightTimeOfDay = new Partial().with(DateTimeFieldType.hourOfDay(), 12).with(DateTimeFieldType.minuteOfHour(), 30); }
public static Time expandPartialMin(Time dt, int size) { for (int i = dt.getPartial().size(); i < size; ++i) { dt.setPartial(dt.getPartial().with(getField(i), getField(i).getField(null).getMinimumValue())); } return dt; } }
public static DateTime expandPartialMin(DateTime dt, int size) { for (int i = dt.getPartial().size(); i < size; ++i) { dt.setPartial(dt.getPartial().with(DateTime.getField(i), DateTime.getField(i).getField(null).getMinimumValue())); } return dt; }
public static Partial resolveWeek(Partial p) { // Figure out week if (p.isSupported(DateTimeFieldType.dayOfMonth()) && p.isSupported(DateTimeFieldType.monthOfYear()) && p.isSupported(DateTimeFieldType.year())) { Instant t = getInstant(p); // return getPartial(t.toInstant(), p.without(DateTimeFieldType.dayOfMonth()).without(DateTimeFieldType.monthOfYear()).with(DateTimeFieldType.weekOfWeekyear(), 1)); return getPartial(t.toInstant(), p.with(DateTimeFieldType.weekOfWeekyear(), 1)); } else return p; }
public static Partial resolveWeek(Partial p) { // Figure out week if (p.isSupported(DateTimeFieldType.dayOfMonth()) && p.isSupported(DateTimeFieldType.monthOfYear()) && p.isSupported(DateTimeFieldType.year())) { Instant t = getInstant(p); // return getPartial(t.toInstant(), p.without(DateTimeFieldType.dayOfMonth()).without(DateTimeFieldType.monthOfYear()).with(DateTimeFieldType.weekOfWeekyear(), 1)); return getPartial(t.toInstant(), p.with(DateTimeFieldType.weekOfWeekyear(), 1)); } else return p; }