Package com.atlassian.bitbucket.timezone
Interface TimeZoneService
- All Superinterfaces:
UserTimeZoneSupplier
Provides access to the time zones used in Bitbucket. There are three types of time zones:
- JVM time zone
-
The time zone configured using the system property
user.timezone
. When not explicitly set the the JVM inherits the the time zone from the launching user. This zone is used for most non-display related tasks, such as log timestamps. It is also the default time zone when no other can be found. SeegetJvmTimeZone()
. - Server time zone
-
The default time zone for Bitbucket. It can be changed at runtime by an administrator. It
is possible for this time zone to not be set. The server time zone is the fallback time zone when a user
has no explicit user time zone defined. See
setServerTimeZone(ZoneId)
andgetServerTimeZone()
. - User time zone
- The time zone as configured by a user. It can be changed at runtime by the user. It is possible for this time zone to not be set.
Given a user the lookup for a time zone returns the first configured time zone of user, server and JVM
in that order. There will always be a JVM time zone to return if all else fails. See
UserTimeZoneSupplier.getTimeZone()
and UserTimeZoneSupplier.getTimeZone(ApplicationUser)
.
- Since:
- 4.6
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturn the configured server time zone.Return the time zone the current user has explicitly configured.void
setServerTimeZone
(ZoneId zone) Set the server time zone.void
setUserTimeZone
(ZoneId zone) Set the time zone of the current user.Methods inherited from interface com.atlassian.bitbucket.timezone.UserTimeZoneSupplier
getTimeZone, getTimeZone
-
Method Details
-
getDefaultTimeZone
- Returns:
- the time zone that will be used if a user has no explicit time zone. Always returns a time zone by falling
back to
getJvmTimeZone()
if necessary.
-
getJvmTimeZone
- Returns:
- the time zone configured for the JVM.
-
getServerTimeZone
Return the configured server time zone.Optional.empty()
will be returned if no server time zone is configured.- Returns:
- the configured server time zone.
-
getUserTimeZone
Return the time zone the current user has explicitly configured. This method will returnOptional.empty()
when no time zone is configured.NOTE: Use
UserTimeZoneSupplier.getTimeZone()
when looking up the time zone that is applicable to the current user (e.g. when rendering dates). ThegetTimeZone
method will always return a time zone by falling back to a set of defaults.- Returns:
- the current user's explicitly configured time zone or
Optional.empty()
if there is none.
-
setServerTimeZone
Set the server time zone.null
may be passed to clear the setting.- Parameters:
zone
- the zone of configure ornull
to clear the setting.
-
setUserTimeZone
Set the time zone of the current user. A user is always able to change its own time zone.- Parameters:
zone
- the time zone to set for the current user.null
may be passed to indicate the user has no configured time zone.- Throws:
AuthorisationException
- if called anonymouslyIllegalUserStateException
- if the context user type does not support setting a time zone.
-