Language

ZoneRules.GetValidOffsets(LocalDateTime) Method

Definition

Gets the offsets applicable at the specified local date-time in these rules.

[Android.Runtime.Register("getValidOffsets", "(Ljava/time/LocalDateTime;)Ljava/util/List;", "", ApiSince=26)]
public System.Collections.Generic.IList<Java.Time.ZoneOffset>? GetValidOffsets(Java.Time.LocalDateTime? localDateTime);
[<Android.Runtime.Register("getValidOffsets", "(Ljava/time/LocalDateTime;)Ljava/util/List;", "", ApiSince=26)>]
member this.GetValidOffsets : Java.Time.LocalDateTime -> System.Collections.Generic.IList<Java.Time.ZoneOffset>

Parameters

localDateTime
LocalDateTime

The local date-time to query for valid offsets. Fixed-offset rules may ignore null; variable rules do not.

Returns

A potentially immutable list of valid offsets. The list has zero entries for a gap, one for a normal local date-time, and two for an overlap; in an overlap, the earlier offset is first.

Attributes

Exceptions

Thrown if localDateTime is null and the rules are not fixed-offset.

Remarks

Gets the offset applicable at the specified local date-time in these rules. The mapping from a local date-time to an offset is not straightforward. There are three cases: Normal, with one valid offset. For the vast majority of the year, the normal case applies, where there is a single valid offset for the local date-time; Gap, with zero valid offsets. This is when clocks jump forward typically due to the spring daylight savings change from "winter" to "summer". In a gap there are local date-time values with no valid offset; Overlap, with two valid offsets. This is when clocks are set back typically due to the autumn daylight savings change from "summer" to "winter". In an overlap there are local date-time values with two valid offsets. Thus, for any given local date-time there can be zero, one or two valid offsets. This method returns that list of valid offsets, which is a list of size 0, 1 or 2. In the case where there are two offsets, the earlier offset is returned at index 0 and the later offset at index 1. There are various ways to handle the conversion from a LocalDateTime.

List<ZoneOffset> validOffsets = rules.getValidOffsets(localDT);
if (validOffsets.size() == 1) {
  // Normal case: only one valid offset
  zoneOffset = validOffsets.get(0);
} else {
  // Gap or Overlap: determine what to do from transition (which will be non-null)
  ZoneOffsetTransition trans = rules.getTransition(localDT);
}

In theory, it is possible for there to be more than two valid offsets. This would happen if clocks to be put back more than once in quick succession. This has never happened in the history of time-zones and thus has no special handling. However, if it were to happen, then the list would return more than 2 entries.

Java reference for java.time.zone.ZoneRules.getValidOffsets.

Applies to