Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

ZoneOffsetTransition — local-time gaps and overlaps

ZoneOffsetTransition describes a change in UTC offset. The isGap() method identifies a gap, while getDateTimeAfter() returns the local date-time at the transition boundary using the new offset.

Version: Java SE 21; repository runtime, production runtime not attested

Syntax

boolean gap = transition.isGap();
LocalDateTime after = transition.getDateTimeAfter();

ZoneOffsetTransition models a change in UTC offset. isGap() returns true for a gap: skipped local times do not exist. A result of false means an overlap: some local times occur twice.

getDateTimeAfter() returns the boundary's LocalDateTime using the new offset, not an Instant. When clocks move backward, its result is earlier than getDateTimeBefore(). A change need not be one hour.

Applications should normally use ZoneRules.getTransition(localDateTime); check for null before calling methods because an ordinary local time has no transition. The example uses of() only as a deterministic demonstration; that factory is intended for constructing ZoneRules, not looking up actual zone changes.

Reference identifiers covered by this entry: ZoneOffsetTransition.isGap, ZoneOffsetTransition.getDateTimeAfter.

Examples

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.zone.ZoneOffsetTransition;

public class Main {
    public static void main(String[] args) {
        ZoneOffsetTransition transition = ZoneOffsetTransition.of(
            LocalDateTime.of(2024, 3, 31, 2, 0),
            ZoneOffset.ofHours(1),
            ZoneOffset.ofHours(2)
        );
        System.out.println(transition.isGap());
        System.out.println(transition.getDateTimeAfter());
    }
}

Result

true
2024-03-31T03:00

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources