@Override protected PartialTime addUnsupported(Period p, int scalar) { return new CompositePartialTime(this, JodaTimeUtils.addForce(base, p, scalar), poy, dow, tod); }
@Override public Instant getJodaTimeInstant() { Partial p = base; if (tod != null) { Partial p2 = tod.getJodaTimePartial(); if (p2 != null && JodaTimeUtils.isCompatible(p, p2)) { p = JodaTimeUtils.combine(p, p2); } } if (dow != null) { Partial p2 = dow.getJodaTimePartial(); if (p2 != null && JodaTimeUtils.isCompatible(p, p2)) { p = JodaTimeUtils.combine(p, p2); } } if (poy != null) { Partial p2 = poy.getJodaTimePartial(); if (p2 != null && JodaTimeUtils.isCompatible(p, p2)) { p = JodaTimeUtils.combine(p, p2); } } return JodaTimeUtils.getInstant(p); }
else if (tod != null) mgf = DateTimeFieldType.halfdayOfDay(); Partial p = (base != null) ? JodaTimeUtils.combineMoreGeneralFields(base, partialRef, mgf) : partialRef; if (p.isSupported(DateTimeFieldType.dayOfWeek())) { p = JodaTimeUtils.resolveDowToDay(p, partialRef); } else if (dow != null) { p = JodaTimeUtils.resolveWeek(p, partialRef);
public static Partial addForce(Partial p, Period d, int scalar) { Instant t = getInstant(p); t = t.withDurationAdded(d.toDurationFrom(INSTANT_ZERO), scalar); return getPartial(t, p); }
@Override public boolean hasTime() { if (base == null) return false; DateTimeFieldType sdft = JodaTimeUtils.getMostSpecific(base); if (sdft != null && JodaTimeUtils.isMoreGeneral(DateTimeFieldType.dayOfMonth(), sdft, base.getChronology())) { return true; } else { return false; } }
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; }
@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 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 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 padMoreSpecificFields(Partial p, Period granularity) DateTimeFieldType msf = getMostSpecific(p); if (isMoreGeneral(msf, DateTimeFieldType.year(), p.getChronology()) || isMoreGeneral(msf, DateTimeFieldType.yearOfCentury(), p.getChronology())) { if (p.isSupported(DateTimeFieldType.yearOfCentury())) { for (int i = 0; i < p2.size(); i++) { DateTimeFieldType fieldType = p2.getFieldType(i); if (msf == null || isMoreSpecific(fieldType, msf, p.getChronology())) { if (!p.isSupported(fieldType)) { if (fieldType == DateTimeFieldType.monthOfYear()) { DurationFieldType mostSpecific = getMostSpecific(granularity); p = discardMoreSpecificFields(p, mostSpecific);
protected boolean appendTimeFormats(DateTimeFormatterBuilder builder, int flags) { boolean alwaysPad = ((flags & FORMAT_PAD_UNKNOWN) != 0); boolean hasTime = hasTime(); DateTimeFieldType sdft = JodaTimeUtils.getMostSpecific(base); if (hasTime) { builder.appendLiteral("T"); if (JodaTimeUtils.hasField(base, DateTimeFieldType.hourOfDay())) { builder.appendHourOfDay(2); } else if (JodaTimeUtils.hasField(base, DateTimeFieldType.clockhourOfDay())) { builder.appendClockhourOfDay(2); } else { builder.appendLiteral(PAD_FIELD_UNKNOWN2); if (JodaTimeUtils.hasField(base, DateTimeFieldType.minuteOfHour())) { builder.appendLiteral(":"); builder.appendMinuteOfHour(2); } else if (alwaysPad || JodaTimeUtils.isMoreGeneral(DateTimeFieldType.minuteOfHour(), sdft, base.getChronology())) { builder.appendLiteral(":"); builder.appendLiteral(PAD_FIELD_UNKNOWN2); if (JodaTimeUtils.hasField(base, DateTimeFieldType.secondOfMinute())) { builder.appendLiteral(":"); builder.appendSecondOfMinute(2); } else if (alwaysPad || JodaTimeUtils.isMoreGeneral(DateTimeFieldType.secondOfMinute(), sdft, base.getChronology())) { builder.appendLiteral(":"); builder.appendLiteral(PAD_FIELD_UNKNOWN2); if (JodaTimeUtils.hasField(base, DateTimeFieldType.millisOfSecond())) { builder.appendLiteral("."); builder.appendMillisOfSecond(3);
Partial p = (base != null) ? JodaTimeUtils.combineMoreGeneralFields(base, partialRef) : partialRef; p = JodaTimeUtils.resolveDowToDay(p, partialRef);
@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 IsoDateTime(IsoDate date, IsoTime time) { this.date = date; this.time = time; base = JodaTimeUtils.combine(date.base, time.base); }
@Override public Duration getDuration() { /* TimeLabel tl = getTimeLabel(); if (tl != null) { return tl.getDuration(); } */ StandardTemporalType tlt = getStandardTemporalType(); if (tlt != null) { return tlt.getDuration(); } return Duration.getDuration(JodaTimeUtils.getJodaTimePeriod(base)); }
@Override public Duration getPeriod() { /* TimeLabel tl = getTimeLabel(); if (tl != null) { return tl.getPeriod(); } */ StandardTemporalType tlt = getStandardTemporalType(); if (tlt != null) { return tlt.getPeriod(); } if (base == null) { return null; } DateTimeFieldType mostGeneral = JodaTimeUtils.getMostGeneral(base); DurationFieldType df = mostGeneral.getRangeDurationType(); // if (df == null) { // df = mostGeneral.getDurationType(); // } if (df != null) { try { return new DurationWithFields(new Period().withField(df, 1)); } catch (Exception ex) { // TODO: Do something intelligent here } } return null; }
for (DateTimeFieldType dtft : dtFieldTypes) { if (p.isSupported(dtft)) { t = new PartialTime(JodaTimeUtils.discardMoreSpecificFields(p, dtft)); for (DateTimeFieldType dtft : dtFieldTypes) { if (instant.isSupported(dtft)) { Partial p2 = JodaTimeUtils.getPartial(instant, p.with(dtft, 1)); t = new PartialTime(JodaTimeUtils.discardMoreSpecificFields(p2, dtft));
@Override public Instant getJodaTimeInstant() { return JodaTimeUtils.getInstant(base); }
public static Partial combineMoreGeneralFields(Partial p1, Partial p2) { return combineMoreGeneralFields(p1, p2, null); }
public static Period getUnsupportedDurationPeriod(Partial p, Period offset) { if (offset == null) { return null; } Set<DurationFieldType> supported = getSupportedDurationFields(p); Period res = null; for (int i = 0; i < offset.size(); i++) { if (!supported.contains(offset.getFieldType(i))) { if (offset.getValue(i) != 0) { if (res == null) { res = new Period(); } res = res.withField(offset.getFieldType(i), offset.getValue(i)); } } } return res; } public static Partial combine(Partial p1, Partial p2) {