/** * <p>Calculates the time distance between this timestamp and given * end timestamp in given SI-unit on the UTC time scale. </p> * * @param end end time point * @param unit time unit defined in UTC time space * @return count of SI-units between this instance and end time point * @throws UnsupportedOperationException if any moment is before 1972 */ /*[deutsch] * <p>Bestimmt den zeitlichen Abstand zu einem Endzeitpunkt in der * angegebenen Zeiteinheit auf der UTC-Zeitskala. </p> * * @param end end time point * @param unit time unit defined in UTC time space * @return count of SI-units between this instance and end time point * @throws UnsupportedOperationException wenn ein Zeitpunkt vor 1972 ist */ public long until( Moment end, SI unit ) { return unit.between(this, end); }
@Override public boolean contains(Object unit) { if ( ((this.scale == POSIX) && TimeUnit.SECONDS.equals(unit)) || ((this.scale == UTC) && SI.SECONDS.equals(unit)) ) { return (this.seconds != 0); } else if ( ((this.scale == POSIX) && TimeUnit.NANOSECONDS.equals(unit)) || ((this.scale == UTC) && SI.NANOSECONDS.equals(unit)) ) { return (this.nanos != 0); } return false; }
return ofSIUnits(secs, fraction); default: throw new UnsupportedOperationException(unit.name());
@Override public long getPartialAmount(Object unit) { if ( ((this.scale == POSIX) && TimeUnit.SECONDS.equals(unit)) || ((this.scale == UTC) && SI.SECONDS.equals(unit)) ) { return Math.abs(this.seconds); } else if ( ((this.scale == POSIX) && TimeUnit.NANOSECONDS.equals(unit)) || ((this.scale == UTC) && SI.NANOSECONDS.equals(unit)) ) { return Math.abs(this.nanos); } return 0; }
private String printRelativeSeconds( Moment t1, Moment t2, long delta ) { if (t1.getPosixTime() >= START_1972 && t2.getPosixTime() >= START_1972) { delta = SI.SECONDS.between(t1, t2); // leap second correction } if (delta == 0) { return UnitPatterns.of(this.locale).getNowWord(); } long amount = Math.abs(delta); String pattern = ( (delta < 0) ? this.getPastPattern(amount, ClockUnit.SECONDS) : this.getFuturePattern(amount, ClockUnit.SECONDS)); return this.format(pattern, amount); }