/** * <p>Adjusts the calendar part of this timestamp. </p> * * @param date new calendar date component * @return changed copy of this timestamp * @see PlainDate#COMPONENT */ /*[deutsch] * <p>Passt die Datumskomponente an. </p> * * @param date new calendar date component * @return changed copy of this timestamp * @see PlainDate#COMPONENT */ public PlainTimestamp with(PlainDate date) { return this.with(CALENDAR_DATE, date); }
/** * <p>Adjusts the wall time part of this timestamp. </p> * * @param time new wall time component * @return changed copy of this timestamp * @see PlainTime#COMPONENT */ /*[deutsch] * <p>Passt die Uhrzeitkomponente an. </p> * * @param time new wall time component * @return changed copy of this timestamp * @see PlainTime#COMPONENT */ public PlainTimestamp with(PlainTime time) { return this.with(WALL_TIME, time); }
PlainTimestamp start = SystemClock.inLocalView().now(); PlainTimestamp end = start.with(PlainTime.COMPONENT.setToNext(PlainTime.of(18, 30))); Duration<ClockUnit> duration = Duration.inClockUnits().between(start, end); String p = PrettyTime.of(Locale.UK).print(duration, TextWidth.WIDE, true, 3); System.out.println(p); // 23 hours, 40 minutes and 1 second
private PlainTimestamp handleEarlier(PlainTimestamp entity) { switch (this.mode) { case ElementOperator.OP_NAV_NEXT: case ElementOperator.OP_NAV_NEXT_OR_SAME: return entity.plus(1, CalendarUnit.DAYS).with(this.value); case ElementOperator.OP_NAV_PREVIOUS: case ElementOperator.OP_NAV_PREVIOUS_OR_SAME: return entity.with(this.value); default: throw new AssertionError("Unknown: " + this.mode); } }
private PlainTimestamp handleLater(PlainTimestamp entity) { switch (this.mode) { case ElementOperator.OP_NAV_NEXT: case ElementOperator.OP_NAV_NEXT_OR_SAME: return entity.with(this.value); case ElementOperator.OP_NAV_PREVIOUS: case ElementOperator.OP_NAV_PREVIOUS_OR_SAME: return entity.minus(1, CalendarUnit.DAYS).with(this.value); default: throw new AssertionError("Unknown: " + this.mode); } }
/** * <p>Adjusts this timestamp by given operator. </p> * * @param operator element-related operator * @return changed copy of this timestamp * @see ChronoEntity#with(net.time4j.engine.ChronoOperator) */ /*[deutsch] * <p>Passt diesen Zeitstempel mit Hilfe des angegebenen Operators an. </p> * * @param operator element-related operator * @return changed copy of this timestamp * @see ChronoEntity#with(net.time4j.engine.ChronoOperator) */ public PlainTimestamp with(ElementOperator<?> operator) { return this.with(operator.onTimestamp()); }
private CalendarOperator(int type) { super(PlainDate.COMPONENT, type); this.tsop = entity -> { PlainDate date = doApply(entity.getCalendarDate()); return entity.with(date); }; }
@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 FullValueOperator(int type) { super(PlainTime.COMPONENT, type); this.tsop = entity -> { PlainTime time = doApply(entity.getWallTime()); if (time.getHour() == 24) { return PlainTimestamp.of( entity.getCalendarDate().plus(1, DAYS), PlainTime.midnightAtStartOfDay()); } else { return entity.with(time); } }; }
@Override public PlainTimestamp translate(java.sql.Timestamp source) { long millis = source.getTime(); // UTC zone if (!WITH_SQL_UTC_CONVERSION) { Moment unixTime = Moment.of( MathUtils.floorDivide(millis, 1000), TimeScale.POSIX); ZonalOffset offset = Timezone.ofSystem().getOffset(unixTime); millis += offset.getIntegralAmount() * 1000; } PlainDate date = PlainDate.of( MathUtils.floorDivide(millis, 86400 * 1000), EpochDays.UNIX); PlainTime time = PlainTime.of(0).plus( MathUtils.floorModulo(millis, 86400 * 1000), ClockUnit.MILLIS); PlainTimestamp ts = PlainTimestamp.of(date, time); return ts.with(PlainTime.NANO_OF_SECOND, source.getNanos()); }
PlainTimestamp ts = moment.in(timezone).with(this.delegate); Moment result = ts.in(timezone);