public override ChronoZonedDateTime<D> WithEarlierOffsetAtOverlap() { ZoneOffsetTransition trans = Zone.Rules.GetTransition(LocalDateTime.From(this)); if (trans != null && trans.Overlap) { ZoneOffset earlierOffset = trans.OffsetBefore; if (earlierOffset.Equals(Offset_Renamed) == false) { return new ChronoZonedDateTimeImpl<>(DateTime, earlierOffset, Zone_Renamed); } } return this; }
public override ChronoZonedDateTime<D> WithLaterOffsetAtOverlap() { ZoneOffsetTransition trans = Zone.Rules.GetTransition(LocalDateTime.From(this)); if (trans != null) { ZoneOffset offset = trans.OffsetAfter; if (offset.Equals(Offset) == false) { return new ChronoZonedDateTimeImpl<>(DateTime, offset, Zone_Renamed); } } return this; }
//----------------------------------------------------------------------- /// <summary> /// Obtains an instance from a local date-time using the preferred offset if possible. /// </summary> /// <param name="localDateTime"> the local date-time, not null </param> /// <param name="zone"> the zone identifier, not null </param> /// <param name="preferredOffset"> the zone offset, null if no preference </param> /// <returns> the zoned date-time, not null </returns> internal static ChronoZonedDateTime<R> ofBest<R>(ChronoLocalDateTimeImpl<R> localDateTime, ZoneId zone, ZoneOffset preferredOffset) where R : ChronoLocalDate { Objects.RequireNonNull(localDateTime, "localDateTime"); Objects.RequireNonNull(zone, "zone"); if (zone is ZoneOffset) { return new ChronoZonedDateTimeImpl<>(localDateTime, (ZoneOffset) zone, zone); } ZoneRules rules = zone.Rules; LocalDateTime isoLDT = LocalDateTime.From(localDateTime); IList<ZoneOffset> validOffsets = rules.GetValidOffsets(isoLDT); ZoneOffset offset; if (validOffsets.Count == 1) { offset = validOffsets[0]; } else if (validOffsets.Count == 0) { ZoneOffsetTransition trans = rules.GetTransition(isoLDT); localDateTime = localDateTime.PlusSeconds(trans.Duration.Seconds); offset = trans.OffsetAfter; } else { if (preferredOffset != null && validOffsets.Contains(preferredOffset)) { offset = preferredOffset; } else { offset = validOffsets[0]; } } Objects.RequireNonNull(offset, "offset"); // protect against bad ZoneRules return new ChronoZonedDateTimeImpl<>(localDateTime, offset, zone); }