public abstract class Timezone extends Object implements Serializable
Loads and keeps timezone data including the rules.
| Modifier and Type | Class and Description |
|---|---|
static class |
Timezone.Cache
Offers some static methods for the configuration of the
timezone cache.
|
static interface |
Timezone.Provider
SPI interface which encapsulates the timezone repository and
provides all necessary data for a given timezone id.
|
| Modifier and Type | Field and Description |
|---|---|
static TransitionStrategy |
DEFAULT_CONFLICT_STRATEGY
This standard strategy which is also used by JDK subtracts
the next defined offset from any local timestamp in order to
calculate the global time.
|
static TransitionStrategy |
STRICT_MODE
In addition to the
standard strategy, this strategy ensures the use of valid local
timestamps. |
| Modifier and Type | Method and Description |
|---|---|
static List<TZID> |
getAvailableIDs()
Gets all available timezone IDs.
|
String |
getDisplayName(NameStyle style,
Locale locale)
Returns the name of this timezone suitable for presentation to
users in given style and locale.
|
abstract TransitionHistory |
getHistory()
Gets the underlying offset transitions and rules if available.
|
abstract TZID |
getID()
Gets the associated timezone identifier.
|
abstract ZonalOffset |
getOffset(GregorianDate localDate,
WallTime localTime)
Calculates the offset for given local timestamp.
|
abstract ZonalOffset |
getOffset(UnixTime ut)
Calculates the offset for given global timestamp.
|
static Set<TZID> |
getPreferredIDs(Locale locale)
Gets a
Set of preferred timezone IDs for given
ISO-3166-country code. |
static String |
getProviderInfo()
Describes the underlying repository with name and optionally
location and version.
|
abstract TransitionStrategy |
getStrategy()
Gets the strategy for resolving local timestamps.
|
abstract boolean |
isDaylightSaving(UnixTime ut)
Queries if given global timestamp matches daylight saving time
in this timezone?
|
abstract boolean |
isInvalid(GregorianDate localDate,
WallTime localTime)
Evaluates if given local timestamp is invalid due to a gap
on the local timeline.
|
static Timezone |
of(String tzid)
Gets the timezone for given identifier.
|
static Timezone |
of(String tzid,
TZID fallback)
Tries to load the timezone with the first given identifer else
with given alternative identifier.
|
static Timezone |
of(TZID tzid)
Gets the timezone for given identifier.
|
static Timezone |
ofSystem()
Gets the system timezone.
|
abstract Timezone |
with(TransitionStrategy strategy)
Creates a copy of this timezone which uses given strategy for
resolving local timestamps.
|
public static final TransitionStrategy DEFAULT_CONFLICT_STRATEGY
This standard strategy which is also used by JDK subtracts the next defined offset from any local timestamp in order to calculate the global time.
getOffset(GregorianDate,WallTime)public static final TransitionStrategy STRICT_MODE
In addition to the standard strategy, this strategy ensures the use of valid local
timestamps.
public static List<TZID> getAvailableIDs()
Gets all available timezone IDs.
public static Set<TZID> getPreferredIDs(Locale locale)
Gets a Set of preferred timezone IDs for given
ISO-3166-country code.
This information is necessary to enable parsing of timezone names and is only available if the olson-module "net.time4j.tz.olson" is accessible in class path.
locale - ISO-3166-alpha-2-country to be evaluatedpublic static Timezone ofSystem()
Gets the system timezone.
The underlying algorithm to determine the system timezone is
primarily based on the system property "user.timezone"
then on the method java.util.TimeZone.getDefault(). If
the system property "net.time4j.allow.system.tz.override"
is set to "true" then the system timezone can be changed
by a combined approach of java.util.TimeZone.setDefault()
and the method Timezone.Cache.refresh(). Otherwise this class
will determine the system timezone only for one time while being
loaded.
Note: If the system timezone cannot be determined (for example due to a wrong property value for "user.timezone") then this method will fall back to UTC timezone..
java.util.TimeZone.getDefault()public static Timezone of(TZID tzid)
Gets the timezone for given identifier.
tzid - timezone id as interfaceIllegalArgumentException - if given timezone cannot be loadedpublic static Timezone of(String tzid)
Gets the timezone for given identifier.
tzid - timezone id as StringIllegalArgumentException - if given timezone cannot be loadedpublic static Timezone of(String tzid, TZID fallback)
Tries to load the timezone with the first given identifer else with given alternative identifier.
If the timezone cannot be loaded with first identifier then
this method will load the timezone using the alternative. In case
of failure, this method will finally load the system timezone.
In contrast to of(TZID), this method never throws any
exception.
tzid - preferred timezone idfallback - alternative timezone idpublic abstract TZID getID()
Gets the associated timezone identifier.
java.util.TimeZone.getID()public abstract ZonalOffset getOffset(UnixTime ut)
Calculates the offset for given global timestamp.
ut - unix timejava.util.TimeZone.getOffset(long)public abstract ZonalOffset getOffset(GregorianDate localDate, WallTime localTime)
Calculates the offset for given local timestamp.
In case of gaps or overlaps, this method uses the standard strategy to get the next defined offset. This behaviour is conform to the JDK.
localDate - local date in timezonelocalTime - local wall time in timezonejava.util.TimeZone.getOffset(int, int, int, int, int, int)public abstract boolean isInvalid(GregorianDate localDate, WallTime localTime)
Evaluates if given local timestamp is invalid due to a gap on the local timeline.
A typical example is the transition from standard to daylight saving time because the clock will be manually adjusted such that the clock is moved forward by usually one hour.
localDate - local date in timezonelocalTime - local wall time in timezonetrue if the local time is not defined due to
transition gaps else falsepublic abstract boolean isDaylightSaving(UnixTime ut)
Queries if given global timestamp matches daylight saving time in this timezone?
The DST correction can be obtained as difference between total offset and raw offset if the raw offset has not changed yet. As alternative the DST correction can be obtained by evaluating the transition offset history.
ut - unix timetrue if the argument represents summer time
else falsejava.util.TimeZone.inDaylightTime(java.util.Date)public abstract TransitionHistory getHistory()
Gets the underlying offset transitions and rules if available.
TransitionHistory or null if there is no
better Provider than java.util.TimeZonepublic static String getProviderInfo()
Describes the underlying repository with name and optionally location and version.
public abstract TransitionStrategy getStrategy()
Gets the strategy for resolving local timestamps.
with(TransitionStrategy)public abstract Timezone with(TransitionStrategy strategy)
Creates a copy of this timezone which uses given strategy for resolving local timestamps.
If this timezone has a fixed offset then the strategy will be
ignored because in this case there can never be a conflict.
Otherwise if there is no public offset transition history then
the only supported strategies are DEFAULT_CONFLICT_STRATEGY
and STRICT_MODE.
strategy - transition strategy for resolving local timestampspublic String getDisplayName(NameStyle style, Locale locale)
Returns the name of this timezone suitable for presentation to users in given style and locale.
If the name is not available then this method will yield the ID of this timezone.
style - name stylelocale - language settingjava.util.TimeZone.getDisplayName(boolean,int,Locale),
Locale.getDefault(),
getID()Copyright © 2014. All rights reserved.