Class TimeZoneFormat
- All Implemented Interfaces:
Freezable<TimeZoneFormat>, Serializable, Cloneable
TimeZoneFormat supports time zone display name formatting and parsing.
An instance of TimeZoneFormat works as a subformatter of SimpleDateFormat,
but you can also directly get a new instance of TimeZoneFormat and
formatting/parsing time zone display names.
ICU implements the time zone display names defined by UTS#35
Unicode Locale Data Markup Language (LDML). TimeZoneNames represents the
time zone display name data model and this class implements the algorithm for actual
formatting and parsing.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classUsed for representing localized GMT time fields in the parsed pattern object.static enumOffset pattern type enum.private static enumNumeric offset field combinationsstatic enumParse option enum, used for specifying optional parse behavior.static enumTime zone display format style enum used by format/parse APIs inTimeZoneFormat.static enumTime type enum used for receiving time type (standard time, daylight time or unknown) inTimeZoneFormatAPIs.private static classImplementsTimeZoneFormatobject cacheNested classes/interfaces inherited from class UFormat
UFormat.SpanFieldNested classes/interfaces inherited from class Format
Format.Field -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate String[]private Object[][]private String[]private Stringprivate Stringprivate Stringprivate Stringprivate TimeZoneGenericNamesprivate ULocaleprivate booleanprivate booleanprivate Stringprivate TimeZoneNamesprivate static TimeZoneFormat.TimeZoneFormatCacheprivate TimeZoneNamesprivate static final EnumSet<TimeZoneGenericNames.GenericNameType> private static final EnumSet<TimeZoneNames.NameType> private static final String[]private static final Stringprivate static final String[]private static final charprivate static final Stringprivate static final Stringprivate static final intprivate static final intprivate static final Stringprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final TimeZoneFormat.GMTOffsetPatternType[]private static final ObjectStreamField[]private static final longprivate static TextTrieMap<String> private static final Stringprivate static final Stringprivate static final intprivate static final Stringprivate static final Stringprivate static TextTrieMap<String> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTimeZoneFormat(ULocale locale) The protected constructor for subclassing. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendOffsetDigits(StringBuilder buf, int n, int minDigits) Appends localized digits to the buffer.private voidclone()Provides for the clone operation.private static StringexpandOffsetPattern(String offsetHM) Appends seconds field to the offset pattern with hour/minutefinal Stringformat(TimeZoneFormat.Style style, TimeZone tz, long date) Returns the display name of the time zone at the given date for the style.format(TimeZoneFormat.Style style, TimeZone tz, long date, Output<TimeZoneFormat.TimeType> timeType) Returns the display name of the time zone at the given date for the style.format(Object obj, StringBuffer toAppendTo, FieldPosition pos) private StringPrivate method returning the time zone's exemplar location string.private StringformatOffsetISO8601(int offset, boolean isBasic, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds) final StringformatOffsetISO8601Basic(int offset, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds) Returns the ISO 8601 basic time zone string for the given offset.final StringformatOffsetISO8601Extended(int offset, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds) Returns the ISO 8601 extended time zone string for the given offset.formatOffsetLocalizedGMT(int offset) Returns the localized GMT(UTC) offset format for the given offset.private StringformatOffsetLocalizedGMT(int offset, boolean isShort) Private method used for localized GMT formatting.formatOffsetShortLocalizedGMT(int offset) Returns the short localized GMT(UTC) offset format for the given offset.private StringformatSpecific(TimeZone tz, TimeZoneNames.NameType stdType, TimeZoneNames.NameType dstType, long date, Output<TimeZoneFormat.TimeType> timeType) Private method returning the time zone's specific format string.freeze()Freezes the object.Returns the default parse options used by thisTimeZoneFormatinstance.Returns the decimal digit characters used for localized GMT format in a single string containing from 0 to 9 in the ascending order.Returns the offset pattern used for localized GMT format.Returns the localized GMT format pattern.Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).static TimeZoneFormatgetInstance(ULocale locale) Returns a frozen instance ofTimeZoneFormatfor the given locale.static TimeZoneFormatgetInstance(Locale locale) Returns a frozen instance ofTimeZoneFormatfor the givenLocale.private StringPrivate method returning the target region.private TimeZoneFormat.TimeTypegetTimeType(TimeZoneNames.NameType nameType) Returns the time type for the given name typeprivate TimeZonegetTimeZoneForOffset(int offset) Creates an instance of TimeZone for the given offsetprivate TimeZoneGenericNamesPrivate method returning the instance of TimeZoneGenericNames used by this object.private StringgetTimeZoneID(String tzID, String mzID) Private method returns a time zone ID.Returns the time zone display name data used by this instance.private TimeZoneNamesPrivate method returning the instance of TZDBTimeZoneNames.private voidinitGMTOffsetPatterns(String[] gmtOffsetPatterns) Initialize localized GMT format offset hour/min/sec patterns.private voidinitGMTPattern(String gmtPattern) Parses the localized GMT pattern string and initialize localized gmt pattern fields including.invalid reference
#_gmtPatternTokensbooleanisFrozen()Determines whether the object has been frozen or not.parse(TimeZoneFormat.Style style, String text, ParsePosition pos, Output<TimeZoneFormat.TimeType> timeType) Returns aTimeZoneby parsing the time zone string according to the parse position, the style and the default parse options.parse(TimeZoneFormat.Style style, String text, ParsePosition pos, EnumSet<TimeZoneFormat.ParseOption> options, Output<TimeZoneFormat.TimeType> timeType) Returns aTimeZoneby parsing the time zone string according to the parse position, the style and the parse options.final TimeZoneReturns aTimeZonefor the given text.final TimeZoneparse(String text, ParsePosition pos) Returns aTimeZoneby parsing the time zone string according to the given parse position.private static intparseAbuttingAsciiOffsetFields(String text, ParsePosition pos, TimeZoneFormat.OffsetFields minFields, TimeZoneFormat.OffsetFields maxFields, boolean fixedHourWidth) Parses offset represented by contiguous ASCII digitsprivate intparseAbuttingOffsetFields(String text, int start, int[] parsedLen) Parses abutting localized GMT offset fields (such as 0800) into offset.private static intparseAsciiOffsetFields(String text, ParsePosition pos, char sep, TimeZoneFormat.OffsetFields minFields, TimeZoneFormat.OffsetFields maxFields) Parses offset represented by ASCII digits and separators.private intparseDefaultOffsetFields(String text, int start, char separator, int[] parsedLen) Parses the input GMT offset fields with the default offset pattern.private StringparseExemplarLocation(String text, ParsePosition pos) Parse an exemplar location string.parseObject(String source, ParsePosition pos) private intparseOffsetDefaultLocalizedGMT(String text, int start, int[] parsedLen) Parses the input text using the default format patterns (e.g.private intparseOffsetFields(String text, int start, boolean isShort, int[] parsedLen) Parses localized GMT offset fields into offset.private intparseOffsetFieldsWithPattern(String text, int start, Object[] patternItems, boolean forceSingleHourDigit, int[] fields) Parses localized GMT offset fields with the given patternprivate intparseOffsetFieldWithLocalizedDigits(String text, int start, int minDigits, int maxDigits, int minVal, int maxVal, int[] parsedLen) Reads an offset field value.final intparseOffsetISO8601(String text, ParsePosition pos) Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 basic or extended time zone string.private static intparseOffsetISO8601(String text, ParsePosition pos, boolean extendedOnly, Output<Boolean> hasDigitOffset) Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 time zone string (basic format, extended format, or UTC indicator).intparseOffsetLocalizedGMT(String text, ParsePosition pos) Returns offset from GMT(UTC) in milliseconds for the given localized GMT offset format string.private intparseOffsetLocalizedGMT(String text, ParsePosition pos, boolean isShort, Output<Boolean> hasDigitOffset) Returns offset from GMT(UTC) in milliseconds for the given localized GMT offset format string.private intparseOffsetLocalizedGMTPattern(String text, int start, boolean isShort, int[] parsedLen) Parse localized GMT format generated by the pattern used by this formatter, except GMT Zero format.private static Object[]parseOffsetPattern(String pattern, String letters) Parse the GMT offset pattern into runtime optimized formatintparseOffsetShortLocalizedGMT(String text, ParsePosition pos) Returns offset from GMT(UTC) in milliseconds for the given short localized GMT offset format string.private static StringparseShortZoneID(String text, ParsePosition pos) Parse a short zone ID.private intparseSingleLocalizedDigit(String text, int start, int[] len) Reads a single decimal digit, either localized digits used by this object or any Unicode numeric character.private static StringparseZoneID(String text, ParsePosition pos) Parse a zone ID.private voidSets the default parse options.setGMTOffsetDigits(String digits) Sets the decimal digit characters used for localized GMT format.setGMTOffsetPattern(TimeZoneFormat.GMTOffsetPatternType type, String pattern) Sets the offset pattern for the given offset type.setGMTPattern(String pattern) Sets the localized GMT format pattern.setGMTZeroFormat(String gmtZeroFormat) Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).setTimeZoneNames(TimeZoneNames tznames) Sets the time zone display name data to this instance.private static String[]toCodePoints(String str) Break input String into String[].private static StringtruncateOffsetPattern(String offsetHM) Truncates minutes field from the offset pattern with hour/minuteprivate static StringUnquotes the message format style pattern.private voidMethods inherited from class Format
format, parseObject
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
ISO_Z_STYLE_FLAG
private static final int ISO_Z_STYLE_FLAG- See Also:
-
ISO_LOCAL_STYLE_FLAG
private static final int ISO_LOCAL_STYLE_FLAG- See Also:
-
_locale
-
_tznames
-
_gmtPattern
-
_gmtOffsetPatterns
-
_gmtOffsetDigits
-
_gmtZeroFormat
-
_parseAllStyles
private boolean _parseAllStyles -
_parseTZDBNames
private boolean _parseTZDBNames -
_gnames
-
_gmtPatternPrefix
-
_gmtPatternSuffix
-
_gmtOffsetPatternItems
-
_abuttingOffsetHoursAndMinutes
private transient boolean _abuttingOffsetHoursAndMinutes -
_region
-
_frozen
private transient volatile boolean _frozen -
_tzdbNames
-
TZID_GMT
- See Also:
-
ALT_GMT_STRINGS
-
DEFAULT_GMT_PATTERN
- See Also:
-
DEFAULT_GMT_ZERO
- See Also:
-
DEFAULT_GMT_DIGITS
-
DEFAULT_GMT_OFFSET_SEP
private static final char DEFAULT_GMT_OFFSET_SEP- See Also:
-
ASCII_DIGITS
- See Also:
-
ISO8601_UTC
- See Also:
-
UNKNOWN_ZONE_ID
- See Also:
-
UNKNOWN_SHORT_ZONE_ID
- See Also:
-
UNKNOWN_LOCATION
- See Also:
-
PARSE_GMT_OFFSET_TYPES
-
MILLIS_PER_HOUR
private static final int MILLIS_PER_HOUR- See Also:
-
MILLIS_PER_MINUTE
private static final int MILLIS_PER_MINUTE- See Also:
-
MILLIS_PER_SECOND
private static final int MILLIS_PER_SECOND- See Also:
-
MAX_OFFSET
private static final int MAX_OFFSET- See Also:
-
MAX_OFFSET_HOUR
private static final int MAX_OFFSET_HOUR- See Also:
-
MAX_OFFSET_MINUTE
private static final int MAX_OFFSET_MINUTE- See Also:
-
MAX_OFFSET_SECOND
private static final int MAX_OFFSET_SECOND- See Also:
-
UNKNOWN_OFFSET
private static final int UNKNOWN_OFFSET- See Also:
-
_tzfCache
-
ALL_SIMPLE_NAME_TYPES
-
ALL_GENERIC_NAME_TYPES
-
ZONE_ID_TRIE
-
SHORT_ZONE_ID_TRIE
-
serialPersistentFields
-
-
Constructor Details
-
TimeZoneFormat
The protected constructor for subclassing.- Parameters:
locale- the locale
-
-
Method Details
-
getInstance
Returns a frozen instance ofTimeZoneFormatfor the given locale.Note: The instance returned by this method is frozen. If you want to customize a TimeZoneFormat, you must use
cloneAsThawed()to get a thawed copy first.- Parameters:
locale- the locale.- Returns:
- a frozen instance of
TimeZoneFormatfor the given locale.
-
getInstance
Returns a frozen instance ofTimeZoneFormatfor the givenLocale.Note: The instance returned by this method is frozen. If you want to customize a TimeZoneFormat, you must use
cloneAsThawed()to get a thawed copy first.- Parameters:
locale- theLocale.- Returns:
- a frozen instance of
TimeZoneFormatfor the given locale.
-
getTimeZoneNames
Returns the time zone display name data used by this instance.- Returns:
- the time zone display name data.
- See Also:
-
getTimeZoneGenericNames
Private method returning the instance of TimeZoneGenericNames used by this object. The instance of TimeZoneGenericNames might not be available until the first use (lazy instantiation) because it is only required for handling generic names (that are not used by DateFormat's default patterns) and it requires relatively heavy one time initialization.- Returns:
- the instance of TimeZoneGenericNames used by this object.
-
getTZDBTimeZoneNames
Private method returning the instance of TZDBTimeZoneNames. The instance if used only for parsing whenTimeZoneFormat.ParseOption.TZ_DATABASE_ABBREVIATIONSis enabled.- Returns:
- an instance of TZDBTimeZoneNames.
-
setTimeZoneNames
Sets the time zone display name data to this instance.- Parameters:
tznames- the time zone display name data.- Returns:
- this object.
- Throws:
UnsupportedOperationException- when this object is frozen.- See Also:
-
getGMTPattern
Returns the localized GMT format pattern.- Returns:
- the localized GMT format pattern.
- See Also:
-
setGMTPattern
Sets the localized GMT format pattern. The pattern must contain a single argument {0}, for example "GMT {0}".- Parameters:
pattern- the localized GMT format pattern string- Returns:
- this object.
- Throws:
IllegalArgumentException- when the pattern string does not contain "{0}"UnsupportedOperationException- when this object is frozen.- See Also:
-
getGMTOffsetPattern
Returns the offset pattern used for localized GMT format.- Parameters:
type- the offset pattern enum- See Also:
-
setGMTOffsetPattern
Sets the offset pattern for the given offset type.- Parameters:
type- the offset pattern.pattern- the pattern string.- Returns:
- this object.
- Throws:
IllegalArgumentException- when the pattern string does not have required time field letters.UnsupportedOperationException- when this object is frozen.- See Also:
-
getGMTOffsetDigits
Returns the decimal digit characters used for localized GMT format in a single string containing from 0 to 9 in the ascending order.- Returns:
- the decimal digits for localized GMT format.
- See Also:
-
setGMTOffsetDigits
Sets the decimal digit characters used for localized GMT format.- Parameters:
digits- a string contains the decimal digit characters from 0 to 9 n the ascending order.- Returns:
- this object.
- Throws:
IllegalArgumentException- when the string did not contain ten characters.UnsupportedOperationException- when this object is frozen.- See Also:
-
getGMTZeroFormat
Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).- Returns:
- the localized GMT string string for GMT(UTC) itself.
- See Also:
-
setGMTZeroFormat
Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).- Parameters:
gmtZeroFormat- the localized GMT format string for GMT(UTC).- Returns:
- this object.
- Throws:
UnsupportedOperationException- when this object is frozen.- See Also:
-
setDefaultParseOptions
Sets the default parse options.Note: By default, an instance of
TimeZoneFormatcreated bygetInstance(ULocale)has no parse options set.- Parameters:
options- the default parse options.- Returns:
- this object.
- See Also:
-
getDefaultParseOptions
Returns the default parse options used by thisTimeZoneFormatinstance.- Returns:
- the default parse options.
- See Also:
-
formatOffsetISO8601Basic
public final String formatOffsetISO8601Basic(int offset, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds) Returns the ISO 8601 basic time zone string for the given offset. For example, "-08", "-0830" and "Z"- Parameters:
offset- the offset from GMT(UTC) in milliseconds.useUtcIndicator- true if ISO 8601 UTC indicator "Z" is used when the offset is 0.isShort- true if shortest form is used.ignoreSeconds- true if non-zero offset seconds is appended.- Returns:
- the ISO 8601 basic format.
- Throws:
IllegalArgumentException- if the specified offset is out of supported range (-24 hours < offset < +24 hours).- See Also:
-
formatOffsetISO8601Extended
public final String formatOffsetISO8601Extended(int offset, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds) Returns the ISO 8601 extended time zone string for the given offset. For example, "-08:00", "-08:30" and "Z"- Parameters:
offset- the offset from GMT(UTC) in milliseconds.useUtcIndicator- true if ISO 8601 UTC indicator "Z" is used when the offset is 0.isShort- true if shortest form is used.ignoreSeconds- true if non-zero offset seconds is appended.- Returns:
- the ISO 8601 extended format.
- Throws:
IllegalArgumentException- if the specified offset is out of supported range (-24 hours < offset < +24 hours).- See Also:
-
formatOffsetLocalizedGMT
Returns the localized GMT(UTC) offset format for the given offset. The localized GMT offset is defined by;- GMT format pattern (e.g. "GMT {0}" - see
getGMTPattern()) - Offset time pattern (e.g. "+HH:mm" - see
getGMTOffsetPattern(GMTOffsetPatternType)) - Offset digits (e.g. "0123456789" - see
getGMTOffsetDigits()) - GMT zero format (e.g. "GMT" - see
getGMTZeroFormat())
- Parameters:
offset- the offset from GMT(UTC) in milliseconds.- Returns:
- the localized GMT format string
- Throws:
IllegalArgumentException- if the specified offset is out of supported range (-24 hours < offset < +24 hours).- See Also:
- GMT format pattern (e.g. "GMT {0}" - see
-
formatOffsetShortLocalizedGMT
Returns the short localized GMT(UTC) offset format for the given offset. The short localized GMT offset is defined by;- GMT format pattern (e.g. "GMT {0}" - see
getGMTPattern()) - Offset time pattern (e.g. "+HH:mm" - see
getGMTOffsetPattern(GMTOffsetPatternType)) - Offset digits (e.g. "0123456789" - see
getGMTOffsetDigits()) - GMT zero format (e.g. "GMT" - see
getGMTZeroFormat())
- Parameters:
offset- the offset from GMT(UTC) in milliseconds.- Returns:
- the short localized GMT format string
- Throws:
IllegalArgumentException- if the specified offset is out of supported range (-24 hours < offset < +24 hours).- See Also:
- GMT format pattern (e.g. "GMT {0}" - see
-
format
Returns the display name of the time zone at the given date for the style.Note: A style may have fallback styles defined. For example, when
GENERIC_LONGis requested, but there is no display name data available forGENERIC_LONGstyle, the implementation may useGENERIC_LOCATIONorLOCALIZED_GMT. See UTS#35 UNICODE LOCALE DATA MARKUP LANGUAGE (LDML) Appendix J: Time Zone Display Name for the details.- Parameters:
style- the style enum (e.g.GENERIC_LONG,LOCALIZED_GMT...)tz- the time zone.date- the date.- Returns:
- the display name of the time zone.
- See Also:
-
format
public String format(TimeZoneFormat.Style style, TimeZone tz, long date, Output<TimeZoneFormat.TimeType> timeType) Returns the display name of the time zone at the given date for the style. This method takes an extra argumentOutput<TimeType> timeTypein addition to the argument list offormat(Style, TimeZone, long). The argument is used for receiving the time type (standard time or daylight saving time, or unknown) actually used for the display name.- Parameters:
style- the style enum (e.g.GENERIC_LONG,LOCALIZED_GMT...)tz- the time zone.date- the date.timeType- the output argument for receiving the time type (standard/daylight/unknown) used for the display name, or specify null if the information is not necessary.- Returns:
- the display name of the time zone.
- See Also:
-
parseOffsetISO8601
Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 basic or extended time zone string. When the given string is not an ISO 8601 time zone string, this method sets the current position as the error index toParsePosition posand returns 0.- Parameters:
text- the text contains ISO 8601 style time zone string (e.g. "-08", "-0800", "-08:00", and "Z") at the position.pos- the position.- Returns:
- the offset from GMT(UTC) in milliseconds for the given ISO 8601 style time zone string.
- See Also:
-
parseOffsetLocalizedGMT
Returns offset from GMT(UTC) in milliseconds for the given localized GMT offset format string. When the given string cannot be parsed, this method sets the current position as the error index toParsePosition posand returns 0.- Parameters:
text- the text contains a localized GMT offset string at the position.pos- the position.- Returns:
- the offset from GMT(UTC) in milliseconds for the given localized GMT offset format string.
- See Also:
-
parseOffsetShortLocalizedGMT
Returns offset from GMT(UTC) in milliseconds for the given short localized GMT offset format string. When the given string cannot be parsed, this method sets the current position as the error index toParsePosition posand returns 0.- Parameters:
text- the text contains a short localized GMT offset string at the position.pos- the position.- Returns:
- the offset from GMT(UTC) in milliseconds for the given short localized GMT offset format string.
- See Also:
-
parse
public TimeZone parse(TimeZoneFormat.Style style, String text, ParsePosition pos, EnumSet<TimeZoneFormat.ParseOption> options, Output<TimeZoneFormat.TimeType> timeType) Returns aTimeZoneby parsing the time zone string according to the parse position, the style and the parse options.- Parameters:
style- the format style.text- the text contains a time zone string at the position.pos- the position.options- the parse options.timeType- The output argument for receiving the time type (standard/daylight/unknown), or specify null if the information is not necessary.- Returns:
- A
TimeZone, or null if the input could not be parsed. - See Also:
-
parse
public TimeZone parse(TimeZoneFormat.Style style, String text, ParsePosition pos, Output<TimeZoneFormat.TimeType> timeType) Returns aTimeZoneby parsing the time zone string according to the parse position, the style and the default parse options.Note: This method is equivalent to
parse(style, text, pos, null, timeType).- Parameters:
style- the format styletext- the text contains a time zone string at the position.pos- the position.timeType- The output argument for receiving the time type (standard/daylight/unknown), or specify null if the information is not necessary.- Returns:
- A
TimeZone, or null if the input could not be parsed. - See Also:
-
parse
Returns aTimeZoneby parsing the time zone string according to the given parse position.Note: This method is equivalent to
parse(Style.GENERIC_LOCATION, text, pos, EnumSet.of(ParseOption.ALL_STYLES), timeType).- Parameters:
text- the text contains a time zone string at the position.pos- the position.- Returns:
- A
TimeZone, or null if the input could not be parsed. - See Also:
-
parse
Returns aTimeZonefor the given text.Note: The behavior of this method is equivalent to
parse(String, ParsePosition).- Parameters:
text- the time zone string- Returns:
- A
TimeZone. - Throws:
ParseException- when the input could not be parsed as a time zone string.- See Also:
-
format
-
formatToCharacterIterator
- Overrides:
formatToCharacterIteratorin classFormat
-
parseObject
- Specified by:
parseObjectin classFormat
-
formatOffsetLocalizedGMT
Private method used for localized GMT formatting.- Parameters:
offset- the zone's UTC offsetisShort- true if the short localized GMT format is desired- Returns:
- the localized GMT string
-
formatOffsetISO8601
private String formatOffsetISO8601(int offset, boolean isBasic, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds) -
formatSpecific
private String formatSpecific(TimeZone tz, TimeZoneNames.NameType stdType, TimeZoneNames.NameType dstType, long date, Output<TimeZoneFormat.TimeType> timeType) Private method returning the time zone's specific format string.- Parameters:
tz- the time zonestdType- the name type used for standard timedstType- the name type used for daylight timedate- the datetimeType- when null, actual time type is set- Returns:
- the time zone's specific format name string
-
formatExemplarLocation
-
getTimeZoneID
Private method returns a time zone ID. If tzID is not null, the value of tzID is returned. If tzID is null, then this method look up a time zone ID for the current region. This is a small helper method used by the parse implementation method- Parameters:
tzID- the time zone ID or nullmzID- the meta zone ID or null- Returns:
- A time zone ID
- Throws:
IllegalArgumentException- when both tzID and mzID are null
-
getTargetRegion
Private method returning the target region. The target regions is determined by the locale of this instance. When a generic name is coming from a meta zone, this region is used for checking if the time zone is a reference zone of the meta zone.- Returns:
- the target region
-
getTimeType
Returns the time type for the given name type- Parameters:
nameType- the name type- Returns:
- the time type (unknown/standard/daylight)
-
initGMTPattern
Parses the localized GMT pattern string and initialize localized gmt pattern fields including. This method must be also called at deserialization time.invalid reference
#_gmtPatternTokens- Parameters:
gmtPattern- the localized GMT pattern string such as "GMT {0}"- Throws:
IllegalArgumentException- when the pattern string does not contain "{0}"
-
unquote
-
initGMTOffsetPatterns
Initialize localized GMT format offset hour/min/sec patterns. This method parses patterns into optimized run-time format. This method must be called at deserialization time.- Parameters:
gmtOffsetPatterns- patterns, String[4]- Throws:
IllegalArgumentException- when patterns are not valid
-
checkAbuttingHoursAndMinutes
private void checkAbuttingHoursAndMinutes() -
parseOffsetPattern
Parse the GMT offset pattern into runtime optimized format- Parameters:
pattern- the offset pattern stringletters- the required pattern letters such as "Hm"- Returns:
- An array of Object. Each array entry is either String (representing pattern literal) or GMTOffsetField (hour/min/sec field)
-
expandOffsetPattern
-
truncateOffsetPattern
-
appendOffsetDigits
Appends localized digits to the buffer.Note: This code assumes that the input number is 0 - 59
- Parameters:
buf- the target buffern- the integer numberminDigits- the minimum digits width
-
getTimeZoneForOffset
Creates an instance of TimeZone for the given offset- Parameters:
offset- the offset- Returns:
- A TimeZone with the given offset
-
parseOffsetLocalizedGMT
private int parseOffsetLocalizedGMT(String text, ParsePosition pos, boolean isShort, Output<Boolean> hasDigitOffset) Returns offset from GMT(UTC) in milliseconds for the given localized GMT offset format string. When the given string cannot be parsed, this method sets the current position as the error index toParsePosition posand returns 0.- Parameters:
text- the text contains a localized GMT offset string at the position.pos- the position.isShort- true if this parser to try the short format firsthasDigitOffset- receiving if the parsed zone string contains offset digits.- Returns:
- the offset from GMT(UTC) in milliseconds for the given localized GMT offset format string.
-
parseOffsetLocalizedGMTPattern
private int parseOffsetLocalizedGMTPattern(String text, int start, boolean isShort, int[] parsedLen) Parse localized GMT format generated by the pattern used by this formatter, except GMT Zero format.- Parameters:
text- the input textstart- the start indexisShort- true if the short localized GMT format is parsed.parsedLen- the parsed length, or 0 on failure.- Returns:
- the parsed offset in milliseconds.
-
parseOffsetFields
Parses localized GMT offset fields into offset.- Parameters:
text- the input textstart- the start indexisShort- true if this is a short format - currently not usedparsedLen- the parsed length, or 0 on failure.- Returns:
- the parsed offset in milliseconds.
-
parseOffsetFieldsWithPattern
private int parseOffsetFieldsWithPattern(String text, int start, Object[] patternItems, boolean forceSingleHourDigit, int[] fields) Parses localized GMT offset fields with the given pattern- Parameters:
text- the input textstart- the start indexpatternItems- the pattern (already itemized)forceSingleHourDigit- true if hours field is parsed as a single digitfields- receives the parsed hours/minutes/seconds- Returns:
- parsed length
-
parseOffsetDefaultLocalizedGMT
Parses the input text using the default format patterns (e.g. "UTC{0}").- Parameters:
text- the input textstart- the start indexparsedLen- the parsed length, or 0 on failure- Returns:
- the parsed offset in milliseconds.
-
parseDefaultOffsetFields
Parses the input GMT offset fields with the default offset pattern.- Parameters:
text- the input textstart- the start indexseparator- the separator character, e.g. ':'parsedLen- the parsed length, or 0 on failure.- Returns:
- the parsed offset in milliseconds.
-
parseAbuttingOffsetFields
Parses abutting localized GMT offset fields (such as 0800) into offset.- Parameters:
text- the input textstart- the start indexparsedLen- the parsed length, or 0 on failure- Returns:
- the parsed offset in milliseconds.
-
parseOffsetFieldWithLocalizedDigits
private int parseOffsetFieldWithLocalizedDigits(String text, int start, int minDigits, int maxDigits, int minVal, int maxVal, int[] parsedLen) Reads an offset field value. This method will stop parsing when 1) number of digits reachesmaxDigits2) just before already parsed number exceedsmaxVal- Parameters:
text- the textstart- the start offsetminDigits- the minimum number of required digitsmaxDigits- the maximum number of digitsminVal- the minimum valuemaxVal- the maximum valueparsedLen- the actual parsed length is set to parsedLen[0], must not be null.- Returns:
- the integer value parsed
-
parseSingleLocalizedDigit
Reads a single decimal digit, either localized digits used by this object or any Unicode numeric character.- Parameters:
text- the textstart- the start indexlen- the actual length read from the text the start index is not a decimal number.- Returns:
- the integer value of the parsed digit, or -1 on failure.
-
toCodePoints
Break input String into String[]. Each array element represents a code point. This method is used for parsing localized digit characters and support characters in Unicode supplemental planes.- Parameters:
str- the string- Returns:
- the array of code points in String[]
-
parseOffsetISO8601
private static int parseOffsetISO8601(String text, ParsePosition pos, boolean extendedOnly, Output<Boolean> hasDigitOffset) Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 time zone string (basic format, extended format, or UTC indicator). When the given string is not an ISO 8601 time zone string, this method sets the current position as the error index toParsePosition posand returns 0.- Parameters:
text- the text contains ISO 8601 style time zone string (e.g. "-08", "-08:00", "Z") at the position.pos- the position.extendedOnly-trueif parsing the text as ISO 8601 extended offset format (e.g. "-08:00"), orfalseto evaluate the text as basic format.hasDigitOffset- receiving if the parsed zone string contains offset digits.- Returns:
- the offset from GMT(UTC) in milliseconds for the given ISO 8601 style time zone string.
-
parseAbuttingAsciiOffsetFields
private static int parseAbuttingAsciiOffsetFields(String text, ParsePosition pos, TimeZoneFormat.OffsetFields minFields, TimeZoneFormat.OffsetFields maxFields, boolean fixedHourWidth) Parses offset represented by contiguous ASCII digitsNote: This method expects the input position is already at the start of ASCII digits and does not parse sign (+/-).
- Parameters:
text- The text contains a sequence of ASCII digitspos- The parse positionminFields- The minimum Fields to be parsedmaxFields- The maximum Fields to be parsedfixedHourWidth- true if hours field must be width of 2- Returns:
- Parsed offset, 0 or positive number.
-
parseAsciiOffsetFields
private static int parseAsciiOffsetFields(String text, ParsePosition pos, char sep, TimeZoneFormat.OffsetFields minFields, TimeZoneFormat.OffsetFields maxFields) Parses offset represented by ASCII digits and separators.Note: This method expects the input position is already at the start of ASCII digits and does not parse sign (+/-).
- Parameters:
text- The textpos- The parse positionsep- The separator characterminFields- The minimum Fields to be parsedmaxFields- The maximum Fields to be parsed- Returns:
- Parsed offset, 0 or positive number.
-
parseZoneID
Parse a zone ID.- Parameters:
text- the text contains a time zone ID string at the position.pos- the position.- Returns:
- The zone ID parsed.
-
parseShortZoneID
Parse a short zone ID.- Parameters:
text- the text contains a time zone ID string at the position.pos- the position.- Returns:
- The zone ID for the parsed short zone ID.
-
parseExemplarLocation
Parse an exemplar location string.- Parameters:
text- the text contains an exemplar location string at the position.pos- the position.- Returns:
- The zone ID for the parsed exemplar location.
-
writeObject
- Parameters:
oos- the object output stream- Throws:
IOException
-
readObject
- Parameters:
ois- the object input stream- Throws:
ClassNotFoundExceptionIOException
-
isFrozen
public boolean isFrozen()Determines whether the object has been frozen or not.- Specified by:
isFrozenin interfaceFreezable<TimeZoneFormat>
-
freeze
Freezes the object.- Specified by:
freezein interfaceFreezable<TimeZoneFormat>- Returns:
- the object itself.
-
cloneAsThawed
Provides for the clone operation. Any clone is initially unfrozen.- Specified by:
cloneAsThawedin interfaceFreezable<TimeZoneFormat>
-
clone
-