import static net.time4j.tz.GapResolver.NEXT_VALID_TIME; import static net.time4j.tz.OverlapResolver.EARLIER_OFFSET; PlainTimestamp tsp = PlainTimestamp.of(2015, 3, 29, 2, 30); Moment nextValidTime = // equivalent of java.time.Instant tsp.in(Timezone.of(EUROPE.BERLIN).with(NEXT_VALID_TIME.and(EARLIER_OFFSET))); tsp = nextValidTime.toZonalTimestamp(EUROPE.BERLIN); System.out.println(tsp); // 2015-03-29T03 (minute is zero and therefore left out here)
if (attributes.contains(Attributes.TRANSITION_STRATEGY)) { TransitionStrategy strategy = attributes.get(Attributes.TRANSITION_STRATEGY); return tsp.in(Timezone.of(tzid).with(strategy)); } else { return tsp.inTimezone(tzid);
/** * <p>Combines this local timestamp with the system timezone to a global * UTC-moment. </p> * * @return global UTC-moment based on this local timestamp interpreted * in system timezone * @since 1.2 * @see Timezone#ofSystem() * @see #inTimezone(TZID) */ /*[deutsch] * <p>Kombiniert diesen lokalen Zeitstempel mit der System-Zeitzone * zu einem UTC-Moment. </p> * * @return global UTC-moment based on this local timestamp interpreted * in system timezone * @since 1.2 * @see Timezone#ofSystem() * @see #inTimezone(TZID) */ public Moment inStdTimezone() { return this.in(Timezone.ofSystem()); }
.get(Attributes.TRANSITION_STRATEGY, Timezone.DEFAULT_CONFLICT_STRATEGY) .using(dst ? OverlapResolver.EARLIER_OFFSET : OverlapResolver.LATER_OFFSET); result = ts.in(Timezone.of(tzid).with(strategy)); } else if (attrs.contains(Attributes.TRANSITION_STRATEGY)) { TransitionStrategy strategy = attrs.get(Attributes.TRANSITION_STRATEGY); result = ts.in(Timezone.of(tzid).with(strategy)); } else { result = ts.inTimezone(tzid);
/** * <p>Converts this instance to a combination of UTC-moment, given timezone and its zonal timestamp. </p> * * <p><strong>Attention:</strong> Due to winter/summer-time-changes the resulting zonal timestamp * ({@link ZonalDateTime#toTimestamp()}) can deviate from this plain timestamp. </p> * * @param tz timezone * @return ZonalDateTime * @since 3.16/4.13 */ /*[deutsch] * <p>Converts this instance to a combination of UTC-moment, given timezone and its zonal timestamp. </p> * * <p><strong>Achtung:</strong> Wegen Winter-/Sommerzeitumstellungen kann der resultierende zonale * Zeitstempel ({@link ZonalDateTime#toTimestamp()}) von diesem Zeitstempel abweichen. </p> * * @param tz timezone * @return ZonalDateTime * @since 3.16/4.13 */ public ZonalDateTime inZonalView(Timezone tz) { Moment m = this.in(tz); return ZonalDateTime.of(m, tz); }
/** * <p>Combines this local timestamp with given timezone to a global * UTC-moment. </p> * * @param tzid timezone id * @return global UTC-moment based on this local timestamp interpreted * in given timezone * @throws IllegalArgumentException if given timezone cannot be loaded * @since 1.2 * @see Timezone#of(TZID) * @see #inStdTimezone() */ /*[deutsch] * <p>Kombiniert diesen lokalen Zeitstempel mit der angegebenen Zeitzone * zu einem UTC-Moment. </p> * * @param tzid timezone id * @return global UTC-moment based on this local timestamp interpreted * in given timezone * @throws IllegalArgumentException if given timezone cannot be loaded * @since 1.2 * @see Timezone#of(TZID) * @see #inStdTimezone() */ public Moment inTimezone(TZID tzid) { return this.in(Timezone.of(tzid)); }
private Moment atFirstMoment(Timezone tz) { TransitionHistory history = tz.getHistory(); if (history == null) { throw new UnsupportedOperationException( "Timezone repository does not expose its transition history: " + Timezone.getProviderInfo()); } ZonalTransition conflict = history.getConflictTransition(this, PlainTime.MIN); if ((conflict != null) && conflict.isGap()) { return Moment.of(conflict.getPosixTime(), TimeScale.POSIX); } return this.at(PlainTime.MIN).in(tz); }
@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; }
@Override public Moment plusPeriod( Moment timepoint, String period, ParseLog plog, AttributeQuery attributes ) { Timezone tz = getTimezone(plog.getRawValues(), attributes); PlainTimestamp tsp = timepoint.toZonalTimestamp(tz.getID()); try { return tsp.plus(Duration.parsePeriod(period)).in(tz); } catch (ParseException ex) { return null; } }
@Override public Moment minusPeriod( Moment timepoint, String period, ParseLog plog, AttributeQuery attributes ) { Timezone tz = getTimezone(plog.getRawValues(), attributes); PlainTimestamp tsp = timepoint.toZonalTimestamp(tz.getID()); try { return tsp.minus(Duration.parsePeriod(period)).in(tz); } catch (ParseException ex) { return null; } }
return tsp.in(tz);