Top Description Inners Fields Constructors Methods
java.time.zone

public final Class ZoneOffsetTransitionRule

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Static Imports
java.time.temporal.TemporalAdjusters.nextOrSame, .TemporalAdjusters.previousOrSame

A rule expressing how to create a transition.

This class allows rules for identifying future transitions to be expressed. A rule might be written in many forms:

These different rule types can be expressed and queried.

Implementation Specification

This class is immutable and thread-safe.

Since
1.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
ZoneOffsetTransitionRule.TimeDefinition

A definition of the way a local time can be converted to the actual transition date-time.

Field Summary

Modifier and TypeField and Description
private final byte
dom

The day-of-month of the month-day of the cutover week.

private final DayOfWeek
dow

The cutover day-of-week, null to retain the day-of-month.

private final Month
month

The month of the month-day of the first day of the cutover week.

private final ZoneOffset
offsetAfter

The offset after the cutover.

private final ZoneOffset
offsetBefore

The offset before the cutover.

private static final long
serialVersionUID

Serialization version.

private final ZoneOffset
standardOffset

The standard offset at the cutover.

private final LocalTime
time

The cutover time in the 'before' offset.

private final ZoneOffsetTransitionRule.TimeDefinition
timeDefinition

The definition of how the local time should be interpreted.

private final boolean
timeEndOfDay

Whether the cutover time is midnight at the end of day.

Constructor Summary

AccessConstructor and Description
pack-priv
ZoneOffsetTransitionRule(Month
the month of the month-day of the first day of the cutover week, not null
month
,
int
the day of the month-day of the cutover week, positive if the week is that day or later, negative if the week is that day or earlier, counting from the last day of the month, from -28 to 31 excluding 0
dayOfMonthIndicator
,
DayOfWeek
the required day-of-week, null if the month-day should not be changed
dayOfWeek
,
LocalTime
the cutover time in the 'before' offset, not null
time
,
boolean
whether the time is midnight at the end of day
timeEndOfDay
,
ZoneOffsetTransitionRule.TimeDefinition
how to interpret the cutover
timeDefinition
,
ZoneOffset
the standard offset in force at the cutover, not null
standardOffset
,
ZoneOffset
the offset before the cutover, not null
offsetBefore
,
ZoneOffset
the offset after the cutover, not null
offsetAfter
)

Creates an instance defining the yearly rule to create transitions between two offsets.

Method Summary

Modifier and TypeMethod and Description
public ZoneOffsetTransition

Returns:

the transition instance, not null
createTransition
(int
the year to create a transition for, not null
year
)

Creates a transition instance for the specified year.

public boolean

Returns:

true if equal
equals
(Object
the other object to compare to, null returns false
otherRule
)

Overrides java.lang.Object.equals.

Checks if this object equals another.

public int

Returns:

the day-of-month indicator, from -28 to 31 excluding 0
getDayOfMonthIndicator
()

Gets the indicator of the day-of-month of the transition.

public DayOfWeek

Returns:

the day-of-week that the transition occurs, null if the rule defines an exact date
getDayOfWeek
()

Gets the day-of-week of the transition.

public LocalTime

Returns:

the local time of day of the transition, not null
getLocalTime
()

Gets the local time of day of the transition which must be checked with isMidnightEndOfDay().

public Month

Returns:

the month of the transition, not null
getMonth
()

Gets the month of the transition.

public ZoneOffset

Returns:

the offset after, not null
getOffsetAfter
()

Gets the offset after the transition.

public ZoneOffset

Returns:

the offset before, not null
getOffsetBefore
()

Gets the offset before the transition.

public ZoneOffset

Returns:

the standard offset, not null
getStandardOffset
()

Gets the standard offset in force at the transition.

public ZoneOffsetTransitionRule.TimeDefinition

Returns:

the time definition, not null
getTimeDefinition
()

Gets the time definition, specifying how to convert the time to an instant.

public int

Returns:

the hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a suitable hash code.

public boolean

Returns:

whether a local time of midnight is at the start or end of the day
isMidnightEndOfDay
()

Is the transition local time midnight at the end of day.

public static ZoneOffsetTransitionRule

Returns:

the rule, not null
of
(Month
the month of the month-day of the first day of the cutover week, not null
month
,
int
the day of the month-day of the cutover week, positive if the week is that day or later, negative if the week is that day or earlier, counting from the last day of the month, from -28 to 31 excluding 0
dayOfMonthIndicator
,
DayOfWeek
the required day-of-week, null if the month-day should not be changed
dayOfWeek
,
LocalTime
the cutover time in the 'before' offset, not null
time
,
boolean
whether the time is midnight at the end of day
timeEndOfDay
,
ZoneOffsetTransitionRule.TimeDefinition
how to interpret the cutover
timeDefinition
,
ZoneOffset
the standard offset in force at the cutover, not null
standardOffset
,
ZoneOffset
the offset before the cutover, not null
offsetBefore
,
ZoneOffset
the offset after the cutover, not null
offsetAfter
)

Obtains an instance defining the yearly rule to create transitions between two offsets.

pack-priv static ZoneOffsetTransitionRule

Returns:

the created object, not null
readExternal
(DataInput
the input stream, not null
in
)

Reads the state from the stream.

private void
readObject(ObjectInputStream
the stream to read
s
)

Defend against malicious streams.

public String

Returns:

a string for debugging, not null
toString
()

Overrides java.lang.Object.toString.

Returns a string describing this object.

pack-priv void
writeExternal(DataOutput
the output stream, not null
out
)

Writes the state to the stream.

private Object

Returns:

the replacing object, not null
writeReplace
()

Writes the object using a dedicated serialized form.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

domback to summary
private final byte dom

The day-of-month of the month-day of the cutover week. If positive, it is the start of the week where the cutover can occur. If negative, it represents the end of the week where cutover can occur. The value is the number of days from the end of the month, such that -1 is the last day of the month, -2 is the second to last day, and so on.

dowback to summary
private final DayOfWeek dow

The cutover day-of-week, null to retain the day-of-month.

monthback to summary
private final Month month

The month of the month-day of the first day of the cutover week. The actual date will be adjusted by the dowChange field.

offsetAfterback to summary
private final ZoneOffset offsetAfter

The offset after the cutover.

offsetBeforeback to summary
private final ZoneOffset offsetBefore

The offset before the cutover.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

standardOffsetback to summary
private final ZoneOffset standardOffset

The standard offset at the cutover.

timeback to summary
private final LocalTime time

The cutover time in the 'before' offset.

timeDefinitionback to summary
private final ZoneOffsetTransitionRule.TimeDefinition timeDefinition

The definition of how the local time should be interpreted.

timeEndOfDayback to summary
private final boolean timeEndOfDay

Whether the cutover time is midnight at the end of day.

Constructor Detail

ZoneOffsetTransitionRuleback to summary
pack-priv ZoneOffsetTransitionRule(Month month, int dayOfMonthIndicator, DayOfWeek dayOfWeek, LocalTime time, boolean timeEndOfDay, ZoneOffsetTransitionRule.TimeDefinition timeDefinition, ZoneOffset standardOffset, ZoneOffset offsetBefore, ZoneOffset offsetAfter)

Creates an instance defining the yearly rule to create transitions between two offsets.

Parameters
month:Month

the month of the month-day of the first day of the cutover week, not null

dayOfMonthIndicator:int

the day of the month-day of the cutover week, positive if the week is that day or later, negative if the week is that day or earlier, counting from the last day of the month, from -28 to 31 excluding 0

dayOfWeek:DayOfWeek

the required day-of-week, null if the month-day should not be changed

time:LocalTime

the cutover time in the 'before' offset, not null

timeEndOfDay:boolean

whether the time is midnight at the end of day

timeDefinition:ZoneOffsetTransitionRule.TimeDefinition

how to interpret the cutover

standardOffset:ZoneOffset

the standard offset in force at the cutover, not null

offsetBefore:ZoneOffset

the offset before the cutover, not null

offsetAfter:ZoneOffset

the offset after the cutover, not null

Exceptions
IllegalArgumentException:
  • if the day of month indicator is invalid
  • if the end of day flag is true when the time is not midnight

Method Detail

createTransitionback to summary
public ZoneOffsetTransition createTransition(int year)

Creates a transition instance for the specified year.

Calculations are performed using the ISO-8601 chronology.

Parameters
year:int

the year to create a transition for, not null

Returns:ZoneOffsetTransition

the transition instance, not null

equalsback to summary
public boolean equals(Object otherRule)

Overrides java.lang.Object.equals.

Checks if this object equals another.

The entire state of the object is compared.

Parameters
otherRule:Object

the other object to compare to, null returns false

Returns:boolean

true if equal

Annotations
@Override
getDayOfMonthIndicatorback to summary
public int getDayOfMonthIndicator()

Gets the indicator of the day-of-month of the transition.

If the rule defines an exact date then the day is the month of that date.

If the rule defines a week where the transition might occur, then the day defines either the start of the end of the transition week.

If the value is positive, then it represents a normal day-of-month, and is the earliest possible date that the transition can be. The date may refer to 29th February which should be treated as 1st March in non-leap years.

If the value is negative, then it represents the number of days back from the end of the month where -1 is the last day of the month. In this case, the day identified is the latest possible date that the transition can be.

Returns:int

the day-of-month indicator, from -28 to 31 excluding 0

getDayOfWeekback to summary
public DayOfWeek getDayOfWeek()

Gets the day-of-week of the transition.

If the rule defines an exact date then this returns null.

If the rule defines a week where the cutover might occur, then this method returns the day-of-week that the month-day will be adjusted to. If the day is positive then the adjustment is later. If the day is negative then the adjustment is earlier.

Returns:DayOfWeek

the day-of-week that the transition occurs, null if the rule defines an exact date

getLocalTimeback to summary
public LocalTime getLocalTime()

Gets the local time of day of the transition which must be checked with isMidnightEndOfDay().

The time is converted into an instant using the time definition.

Returns:LocalTime

the local time of day of the transition, not null

getMonthback to summary
public Month getMonth()

Gets the month of the transition.

If the rule defines an exact date then the month is the month of that date.

If the rule defines a week where the transition might occur, then the month if the month of either the earliest or latest possible date of the cutover.

Returns:Month

the month of the transition, not null

getOffsetAfterback to summary
public ZoneOffset getOffsetAfter()

Gets the offset after the transition.

Returns:ZoneOffset

the offset after, not null

getOffsetBeforeback to summary
public ZoneOffset getOffsetBefore()

Gets the offset before the transition.

Returns:ZoneOffset

the offset before, not null

getStandardOffsetback to summary
public ZoneOffset getStandardOffset()

Gets the standard offset in force at the transition.

Returns:ZoneOffset

the standard offset, not null

getTimeDefinitionback to summary
public ZoneOffsetTransitionRule.TimeDefinition getTimeDefinition()

Gets the time definition, specifying how to convert the time to an instant.

The local time can be converted to an instant using the standard offset, the wall offset or UTC.

Returns:ZoneOffsetTransitionRule.TimeDefinition

the time definition, not null

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a suitable hash code.

Returns:int

the hash code

Annotations
@Override
isMidnightEndOfDayback to summary
public boolean isMidnightEndOfDay()

Is the transition local time midnight at the end of day.

The transition may be represented as occurring at 24:00.

Returns:boolean

whether a local time of midnight is at the start or end of the day

ofback to summary
public static ZoneOffsetTransitionRule of(Month month, int dayOfMonthIndicator, DayOfWeek dayOfWeek, LocalTime time, boolean timeEndOfDay, ZoneOffsetTransitionRule.TimeDefinition timeDefinition, ZoneOffset standardOffset, ZoneOffset offsetBefore, ZoneOffset offsetAfter)

Obtains an instance defining the yearly rule to create transitions between two offsets.

Applications should normally obtain an instance from ZoneRules. This factory is only intended for use when creating ZoneRules.

Parameters
month:Month

the month of the month-day of the first day of the cutover week, not null

dayOfMonthIndicator:int

the day of the month-day of the cutover week, positive if the week is that day or later, negative if the week is that day or earlier, counting from the last day of the month, from -28 to 31 excluding 0

dayOfWeek:DayOfWeek

the required day-of-week, null if the month-day should not be changed

time:LocalTime

the cutover time in the 'before' offset, not null

timeEndOfDay:boolean

whether the time is midnight at the end of day

timeDefinition:ZoneOffsetTransitionRule.TimeDefinition

how to interpret the cutover

standardOffset:ZoneOffset

the standard offset in force at the cutover, not null

offsetBefore:ZoneOffset

the offset before the cutover, not null

offsetAfter:ZoneOffset

the offset after the cutover, not null

Returns:ZoneOffsetTransitionRule

the rule, not null

Exceptions
IllegalArgumentException:
  • if the day of month indicator is invalid
  • if the end of day flag is true when the time is not midnight
  • if time.getNano() returns non-zero value
readExternalback to summary
pack-priv static ZoneOffsetTransitionRule readExternal(DataInput in) throws IOException

Reads the state from the stream.

Parameters
in:DataInput

the input stream, not null

Returns:ZoneOffsetTransitionRule

the created object, not null

Exceptions
IOException:
if an error occurs
readObjectback to summary
private void readObject(ObjectInputStream s) throws InvalidObjectException

Defend against malicious streams.

Parameters
s:ObjectInputStream

the stream to read

Exceptions
InvalidObjectException:
always
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string describing this object.

Returns:String

a string for debugging, not null

Annotations
@Override
writeExternalback to summary
pack-priv void writeExternal(DataOutput out) throws IOException

Writes the state to the stream.

Parameters
out:DataOutput

the output stream, not null

Exceptions
IOException:
if an error occurs
writeReplaceback to summary
private Object writeReplace()

Writes the object using a dedicated serialized form.

Returns:Object

the replacing object, not null

Serial data
Refer to the serialized form of ZoneRules.writeReplace for the encoding of epoch seconds and offsets.
out.writeByte(3);                // identifies a ZoneOffsetTransitionRule
     final int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
     final int stdOffset = standardOffset.getTotalSeconds();
     final int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
     final int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
     final int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
     final int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
     final int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
     final int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
     final int dowByte = (dow == null ? 0 : dow.getValue());
     int b = (month.getValue() << 28) +          // 4 bits
             ((dom + 32) << 22) +                // 6 bits
             (dowByte << 19) +                   // 3 bits
             (timeByte << 14) +                  // 5 bits
             (timeDefinition.ordinal() << 12) +  // 2 bits
             (stdOffsetByte << 4) +              // 8 bits
             (beforeByte << 2) +                 // 2 bits
             afterByte;                          // 2 bits
     out.writeInt(b);
     if (timeByte == 31) {
         out.writeInt(timeSecs);
     }
     if (stdOffsetByte == 255) {
         out.writeInt(stdOffset);
     }
     if (beforeByte == 3) {
         out.writeInt(offsetBefore.getTotalSeconds());
     }
     if (afterByte == 3) {
         out.writeInt(offsetAfter.getTotalSeconds());
     }

java.time.zone back to summary

public final Enum ZoneOffsetTransitionRule.TimeDefinition

extends Enum<ZoneOffsetTransitionRule.TimeDefinition>
Class Inheritance

A definition of the way a local time can be converted to the actual transition date-time.

Time zone rules are expressed in one of three ways:

Field Summary

Modifier and TypeField and Description
public static final ZoneOffsetTransitionRule.TimeDefinition
STANDARD

The local date-time is expressed in terms of the standard offset.

public static final ZoneOffsetTransitionRule.TimeDefinition
UTC

The local date-time is expressed in terms of the UTC offset.

public static final ZoneOffsetTransitionRule.TimeDefinition
WALL

The local date-time is expressed in terms of the wall offset.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public LocalDateTime

Returns:

the date-time relative to the wall/before offset, not null
createDateTime
(LocalDateTime
the local date-time, not null
dateTime
,
ZoneOffset
the standard offset, not null
standardOffset
,
ZoneOffset
the wall offset, not null
wallOffset
)

Converts the specified local date-time to the local date-time actually seen on a wall clock.

public static ZoneOffsetTransitionRule.TimeDefinition
public static ZoneOffsetTransitionRule.TimeDefinition[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

STANDARDback to summary
public static final ZoneOffsetTransitionRule.TimeDefinition STANDARD

The local date-time is expressed in terms of the standard offset.

UTCback to summary
public static final ZoneOffsetTransitionRule.TimeDefinition UTC

The local date-time is expressed in terms of the UTC offset.

WALLback to summary
public static final ZoneOffsetTransitionRule.TimeDefinition WALL

The local date-time is expressed in terms of the wall offset.

Constructor Detail

TimeDefinitionback to summary
private TimeDefinition()

Method Detail

createDateTimeback to summary
public LocalDateTime createDateTime(LocalDateTime dateTime, ZoneOffset standardOffset, ZoneOffset wallOffset)

Converts the specified local date-time to the local date-time actually seen on a wall clock.

This method converts using the type of this enum. The output is defined relative to the 'before' offset of the transition.

The UTC type uses the UTC offset. The STANDARD type uses the standard offset. The WALL type returns the input date-time. The result is intended for use with the wall-offset.

Parameters
dateTime:LocalDateTime

the local date-time, not null

standardOffset:ZoneOffset

the standard offset, not null

wallOffset:ZoneOffset

the wall offset, not null

Returns:LocalDateTime

the date-time relative to the wall/before offset, not null

valueOfback to summary
public static ZoneOffsetTransitionRule.TimeDefinition valueOf(String name)
valuesback to summary
public static ZoneOffsetTransitionRule.TimeDefinition[] values()