Class ZonalOffset
- All Implemented Interfaces:
Serializable,Comparable<ZonalOffset>,TZID
Represents the shift of a local timestamp relative to UTC timezone usually in full seconds.
Following rule is the guideline (all data in seconds):
[Total Offset] = [Local Wall Time] - [POSIX Time]
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic ZonalOffsetConstant for the UTC timezone representing a shift of0seconds with the canonical representation "Z". -
Method Summary
Modifier and TypeMethodDescriptionstatic ZonalOffsetatLongitude(BigDecimal longitude)Creates a new shift based on a geographical longitude.static ZonalOffsetatLongitude(OffsetSign sign, int degrees, int arcMinutes, double arcSeconds)Creates a new shift based on a geographical longitude.Returns a long canonical representation of this shift.intcompareTo(ZonalOffset obj)Compares the whole state with sign, hours, minutes, seconds and fractional seconds in ascending order.booleanCompares the whole state.intReturns the hour part of this shift as absolute amount.intReturns the minute part of this shift as absolute amount.intReturns the second part of this shift as absolute amount.intReturns the fractional second part of this shift in nanoseconds.intTotal shift in integer seconds without fractional part.getSign()Return the sign of this zonal shift.getStdFormatPattern(Locale locale)Obtains a typical localized format pattern in minute precision.inthashCode()Calculates the hash value.static ZonalOffsetofHours(OffsetSign sign, int hours)Static factory method for a shift which has the given full hour part.static ZonalOffsetofHoursMinutes(OffsetSign sign, int hours, int minutes)Static factory method for a shift which has given hour and minute parts.static ZonalOffsetofTotalSeconds(int total)Creates a shift of the local time relative to UTC timezone in integer seconds.static ZonalOffsetofTotalSeconds(int total, int fraction)Creates a shift of the local time relative to UTC timezone in integer seconds or fractional seconds.static ZonalOffsetInterpretes a canonical representation as zonal offset.toString()Returns a complete short representation of this shift including the sign.
-
Field Details
-
UTC
Constant for the UTC timezone representing a shift of
0seconds with the canonical representation "Z".
-
-
Method Details
-
atLongitude
Creates a new shift based on a geographical longitude.
Note that fractional offsets are not used in context of timezones, but can only be applied to conversions between
PlainTimestampandMoment.- Parameters:
longitude- geographical longitude in degrees defined in range-180.0 <= longitude <= 180.0- Returns:
- zonal offset in decimal precision
- Throws:
IllegalArgumentException- if range check fails
-
atLongitude
public static ZonalOffset atLongitude(OffsetSign sign, int degrees, int arcMinutes, double arcSeconds)Creates a new shift based on a geographical longitude.
Note that fractional offsets are not used in context of timezones, but can only be applied to conversions between
PlainTimestampandMoment.- Parameters:
sign- sign of shift relative to zero meridiandegrees- geographical length in degrees, defined in range0 <= degrees <= 180arcMinutes- arc minute part (0 <= arcMinutes <= 59)arcSeconds- arc second part (0.0 <= arcSeconds < 60.0)- Returns:
- zonal offset in decimal precision
- Throws:
IllegalArgumentException- if range check fails (also if total absolute offset goes beyond 180 degrees)- Since:
- 4.26/3.30
- See Also:
atLongitude(BigDecimal)
-
ofHours
Static factory method for a shift which has the given full hour part.
Is equivalent to
ofHoursMinutes(sign, hours, 0).- Parameters:
sign- sign of shift relative to zero meridianhours- hour part (0 <= hours <= 18)- Returns:
- zonal offset in hour precision
- Throws:
IllegalArgumentException- if range check fails- See Also:
ofHoursMinutes(OffsetSign, int, int)
-
ofHoursMinutes
Static factory method for a shift which has given hour and minute parts.
The given numerical values are identical to the numerical parts of the canonical representation ±hh:mm". The second part is always
0. Only values in the range-18:00 <= [total-offset] <= +18:00are allowed. When calculating the total offset the sign relates to both hour and minute part. Example: The expressionZonalOffset.ofHoursMinutes(BEHIND_UTC, 4, 30)has the representation-04:30and a total shift in seconds of-(4 * 3600 + 30 * 60) = 16200.- Parameters:
sign- sign ofHoursMinutes shift relative to zero meridianhours- hour part (0 <= hours <= 18)minutes- minute part (0 <= minutes <= 59)- Returns:
- zonal offset in minute precision
- Throws:
IllegalArgumentException- if range check fails
-
ofTotalSeconds
Creates a shift of the local time relative to UTC timezone in integer seconds.
- Parameters:
total- total shift in seconds defined in range-18 * 3600 <= total <= 18 * 3600- Returns:
- zonal offset in second precision
- Throws:
IllegalArgumentException- if range check fails- See Also:
getIntegralAmount()
-
ofTotalSeconds
Creates a shift of the local time relative to UTC timezone in integer seconds or fractional seconds.
Note that fractional offsets are not used in context of timezones, but can only be applied to conversions between
PlainTimestampandMoment.- Parameters:
total- total shift in seconds defined in range-18 * 3600 <= total <= 18 * 3600fraction- fraction of second- Returns:
- zonal offset in (sub-)second precision
- Throws:
IllegalArgumentException- if any arguments are out of range or have different signs- See Also:
getIntegralAmount(),getFractionalAmount()
-
getSign
Return the sign of this zonal shift.
- Returns:
BEHIND_UTCif sign is negative elseAHEAD_OF_UTC
-
getAbsoluteHours
public int getAbsoluteHours()Returns the hour part of this shift as absolute amount.
- Returns:
- absolute hour part in range
0 <= x <= 18 - See Also:
getSign()
-
getAbsoluteMinutes
public int getAbsoluteMinutes()Returns the minute part of this shift as absolute amount.
- Returns:
- absolute minute part in range
0 <= x <= 59 - See Also:
getSign()
-
getAbsoluteSeconds
public int getAbsoluteSeconds()Returns the second part of this shift as absolute amount.
- Returns:
- absolute second part in range
0 <= x <= 59 - See Also:
getSign()
-
getIntegralAmount
public int getIntegralAmount()Total shift in integer seconds without fractional part.
- Returns:
- integral part in seconds
-18 * 3600 <= x <= 18 * 3600 - See Also:
getFractionalAmount()
-
getFractionalAmount
public int getFractionalAmount()Returns the fractional second part of this shift in nanoseconds.
Only longitudinal offsets may have fractional parts.
- Returns:
- fractional part in range
-999999999 <= x <= 999999999 - See Also:
getIntegralAmount()
-
compareTo
Compares the whole state with sign, hours, minutes, seconds and fractional seconds in ascending order.
Shifts with sign west for Greenwich (behind UTC) are considered as smaller than shifts with sign east for Greenwich (ahead of UTC).
The natural order is consistent with
equals().- Specified by:
compareToin interfaceComparable<ZonalOffset>
-
equals
Compares the whole state.
-
hashCode
public int hashCode()Calculates the hash value.
-
toString
Returns a complete short representation of this shift including the sign.
Notes: If there are only full minutes or hours the representation is exactly as described in ISO-8601. Another long canonical representation can be obtained by the method
canonical(). -
canonical
Returns a long canonical representation of this shift.
Notes: If this instance denotes the UTC timezone then this method will yield the string "Z". Another short canonical representation can be obtained by the method
toString().- Specified by:
canonicalin interfaceTZID- Returns:
- String in format "UTC±hh:mm" or "UTC±hh:mm:ss" if there is a second part or "UTC±hh:mm:ss.fffffffff" if any fractional part exists or "Z" in timezone UTC
- See Also:
toString()
-
parse
Interpretes a canonical representation as zonal offset.
All string produced by the methods
canonical()ortoString()are supported. Due to the technical nature of canonical representations this method is not designed to parse any kind of user-defined input, especially the use of GMT-prefix is NOT canonical and outdated from a scientific point of view.Examples for supported formats:
- UTC+5
- UTC+05
- UTC+5:30
- UTC+05:30
- UTC+5:30:21
- UTC+05:30:21
- UTC+5:30:21.123456789
- UTC+05:30:21.123456789
- +5
- +05
- +5:30
- +05:30
- +5:30:21
- +05:30:21
- +5:30:21.123456789
- +05:30:21.123456789
Note: All formats containing only the hour or the hour with only one digit are first supported in version 3.1 or later.
- Parameters:
canonical- zonal offset in canonical form to be parsed- Returns:
- parsed
ZonalOffset - Throws:
IllegalArgumentException- if given input is not canonical- Since:
- 2.2
- See Also:
canonical(),toString()
-
getStdFormatPattern
Obtains a typical localized format pattern in minute precision.
The character "±" represents a localized offset sign. And the double letters "hh" and "mm" represent localized digits of hour respective minute part of the offset. All other characters are to be interpreted as literals. Many locales return the format "GMT±hh:mm".
This method is mainly designed for the internal use of the expert format engine of Time4J.
- Parameters:
locale- language setting- Returns:
- localized offset pattern
- Since:
- 3.23/4.19
-