@Override public int hashCode() { long value = (this.posixTime ^ (this.posixTime >>> 32)); return (19 * ((int) value) + 37 * this.getNanosecond()); }
@Override public int getNanosecond(TimeScale scale) { return this.moment.getNanosecond(scale); }
@Override public int getNanosecond() { return this.moment.getNanosecond(); }
@Override public Integer getValue(Moment context) { return Integer.valueOf(context.getNanosecond()); }
@Override public int compareTo(Moment moment) { long u1 = this.getElapsedTimeUTC(); long u2 = moment.getElapsedTimeUTC(); if (u1 < u2) { return -1; } else if (u1 > u2) { return 1; } else { int result = this.getNanosecond() - moment.getNanosecond(); return ((result > 0) ? 1 : ((result < 0) ? -1 : 0)); } }
@Override public Instant from(Moment moment) { return Instant.ofEpochSecond(moment.getPosixTime(), moment.getNanosecond()); }
@Override public Moment withValue( Moment context, Long value, boolean lenient ) { if (value == null) { throw new IllegalArgumentException("Missing elapsed seconds."); } return Moment.of( value.longValue(), context.getNanosecond(), TimeScale.POSIX); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (obj instanceof Moment) { Moment that = (Moment) obj; if (this.posixTime != that.posixTime) { return false; } if (LeapSeconds.getInstance().isEnabled()) { return (this.fraction == that.fraction); } else { return (this.getNanosecond() == that.getNanosecond()); } } else { return false; } }
@Override public java.sql.Timestamp from(Moment moment) { java.sql.Timestamp sql = new java.sql.Timestamp(MathUtils.safeMultiply(moment.getPosixTime(), 1000)); sql.setNanos(moment.getNanosecond()); return sql; }
/** * Serialisierungsmethode. * * @param out output stream * @throws IOException */ void writeTimestamp(DataOutput out) throws IOException { int header = SPX.MOMENT_TYPE; header <<= 4; if (this.isPositiveLS()) { header |= 1; } int fp = this.getNanosecond(); if (fp > 0) { header |= 2; } out.writeByte(header); out.writeLong(this.posixTime); if (fp > 0) { out.writeInt(fp); } }
private double getModernUT() { PlainDate date = this.getDateUTC(); double utValue = this.getElapsedTimeUTC(); utValue += 42.184; utValue += (this.getNanosecond() / (MRD * 1.0)); utValue -= TimeScale.deltaT(date); long ut = (long) Math.floor(utValue); if (Double.compare(MRD - (utValue - ut) * MRD, 1.0) < 0) { return ut + 1; // prevents rounding errors } return utValue; }
private PlainTime getTimeUTC() { int timeOfDay = getTimeOfDay(this); int minutes = timeOfDay / 60; int hour = minutes / 60; int minute = minutes % 60; int second = timeOfDay % 60; int nano = this.getNanosecond(); return PlainTime.of(hour, minute, second, nano); }
@Override public Date from(Moment target) { long posixTime = target.getPosixTime(); int fraction = target.getNanosecond(); long millis = MathUtils.safeAdd( MathUtils.safeMultiply(posixTime, 1000), fraction / MIO); return new Date(millis); }
@Override public Long from(Moment moment) { long posixTime = moment.getPosixTime(); int fraction = moment.getNanosecond(); return Long.valueOf( MathUtils.safeAdd( MathUtils.safeMultiply(posixTime, 1000), fraction / MIO)); }
this.posixTime, POSIX_UTC_DELTA - UTC_TAI_DELTA), this.getNanosecond(), scale ); this.posixTime, POSIX_UTC_DELTA), this.getNanosecond(), scale ); this.posixTime, POSIX_GPS_DELTA), this.getNanosecond(), scale );
@Override public TimeUnit getValue(Moment context) { int f = context.getNanosecond(); if (f != 0) { if ((f % MIO) == 0) { return TimeUnit.MILLISECONDS; } else if ((f % 1000) == 0) { return TimeUnit.MICROSECONDS; } else { return TimeUnit.NANOSECONDS; } } long secs = context.posixTime; if (Math.floorMod(secs, 86400) == 0) { return TimeUnit.DAYS; } else if (Math.floorMod(secs, 3600) == 0) { return TimeUnit.HOURS; } else if (Math.floorMod(secs, 60) == 0) { return TimeUnit.MINUTES; } else { return TimeUnit.SECONDS; } }
int nano = this.getNanosecond();
@Override public Moment addTo( Moment context, long amount ) { if (this.unit.compareTo(TimeUnit.SECONDS) >= 0) { long secs = Math.multiplyExact(amount, this.unit.toSeconds(1)); return Moment.of( Math.addExact(context.getPosixTime(), secs), context.getNanosecond(), POSIX ); } else { // MILLIS, MICROS, NANOS long nanos = Math.multiplyExact(amount, this.unit.toNanos(1)); long sum = Math.addExact(context.getNanosecond(), nanos); int nano = (int) Math.floorMod(sum, MRD); long second = Math.floorDiv(sum, MRD); return Moment.of( Math.addExact(context.getPosixTime(), second), nano, POSIX ); } }
long instantNanos = Math.multiplyExact(utc, MRD) + time.getNanosecond(TimeScale.UTC); long newOffset = Math.subtractExact(instantNanos, compare);
break; case MILLISECONDS: int f3 = (context.getNanosecond() / MIO) * MIO; result = Moment.of(context.posixTime, f3, TimeScale.POSIX); break; case MICROSECONDS: int f6 = (context.getNanosecond() / 1000) * 1000; result = Moment.of(context.posixTime, f6, TimeScale.POSIX); break;