@SuppressWarnings("unchecked") private static Moment add( Moment moment, MachineTime<?> duration ) { if (duration.getScale() == TimeScale.UTC) { MachineTime<SI> mt = (MachineTime<SI>) duration; return moment.plus(mt); } else { MachineTime<TimeUnit> mt = (MachineTime<TimeUnit>) duration; return moment.plus(mt); } }
/** * <p>Adds given real time to this timestamp on the UTC time scale. </p> * * @param realTime real time defined in UTC time space * @return changed copy of this instance * @throws UnsupportedOperationException if either this moment or the result are before 1972 * @throws ArithmeticException in case of overflow * @since 3.23/4.19 */ /*[deutsch] * <p>Addiert die angegebene Realzeit zur UTC-Zeit dieses Zeitstempels. </p> * * @param realTime real time defined in UTC time space * @return changed copy of this instance * @throws UnsupportedOperationException if either this moment or the result are before 1972 * @throws ArithmeticException in case of overflow * @since 3.23/4.19 */ public Moment plus(RealTime<SI> realTime) { return this.plus(realTime.getSeconds(), SI.SECONDS).plus(realTime.getFraction(), SI.NANOSECONDS); }
/** * <p>Subtracts an amount of given SI-unit from this timestamp * on the UTC time scale. </p> * * @param amount amount in SI-units to be subtracted * @param unit time unit defined in UTC time space * @return changed copy of this instance * @throws UnsupportedOperationException if either this moment or the result are before 1972 * @throws ArithmeticException in case of overflow */ /*[deutsch] * <p>Subtrahiert einen Betrag in der angegegebenen Zeiteinheit von der * UTC-Zeit dieses Zeitstempels. </p> * * @param amount amount in SI-units to be subtracted * @param unit time unit defined in UTC time space * @return changed copy of this instance * @throws UnsupportedOperationException if either this moment or the result are before 1972 * @throws ArithmeticException in case of overflow */ public Moment minus( long amount, SI unit ) { return this.plus(Math.negateExact(amount), unit); }
+ timezone.getOffset(moment)); } else if (getMaxSecondOfMinute(moment) == 60) { return moment.plus( Math.subtractExact(60, this.extractOld(moment)), SECONDS); return moment.plus(amount, SECONDS); case 1000: return moment.plus( Math.multiplyExact(MIO, amount), NANOSECONDS); case MIO: return moment.plus( Math.multiplyExact(1000, amount), NANOSECONDS); case MRD: return moment.plus(amount, NANOSECONDS); default: throw new AssertionError(); case ElementOperator.OP_CEILING: if (moment.isLeapSecond()) { result = result.plus(1, SI.SECONDS);
@Override public <V> V getMaximum(ChronoElement<V> element) { V max; if (this.timestamp.contains(element)) { max = this.timestamp.getMaximum(element); } else { max = this.moment.getMaximum(element); } if ( (element == SECOND_OF_MINUTE) && (this.timestamp.getYear() >= 1972) ) { PlainTimestamp ts = this.timestamp.with(element, max); if (!this.zone.isInvalid(ts, ts)) { Moment transformed = ts.in(this.zone); Moment test = transformed.plus(1, SI.SECONDS); if (test.isLeapSecond()) { return element.getType().cast(Integer.valueOf(60)); } } } return max; }
private static Moment moveEventuallyToLS(Moment adjusted) { PlainDate date = adjusted.getDateUTC(); PlainTime time = adjusted.getTimeUTC(); if ( (LeapSeconds.getInstance().getShift(date) == 1) && (time.getHour() == 23) && (time.getMinute() == 59) && (time.getSecond() == 59) ) { return adjusted.plus(1, SI.SECONDS); } else { return adjusted; } }
@Override public Moment apply(Moment timepoint) { LeapSeconds ls = LeapSeconds.getInstance(); if (ls.isEnabled()) { long utc = timepoint.getElapsedTime(TimeScale.UTC); LeapSecondEvent event = ls.getNextEvent(utc); if (event != null) { PlainTimestamp tsp = PlainDate.from(event.getDate()).atTime(23, 59, 59); return tsp.atUTC().plus(event.getShift(), SECONDS); } } return null; }
return result.plus(1, SI.SECONDS); } else { return result;
moment = moment.plus(1, SI.SECONDS); if (!moment.isLeapSecond()) { throw new IllegalArgumentException("Parsed leap second is invalid.");
test = result.plus(1, SECONDS); } else { test =