public interface

TimeZoneService

implements UserTimeZoneSupplier
com.atlassian.bitbucket.timezone.TimeZoneService

Class Overview

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. See getJvmTimeZone().
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) and getServerTimeZone().
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 getTimeZone() and getTimeZone(ApplicationUser).

Summary

Public Methods
@Nonnull ZoneId getDefaultTimeZone()
@Nonnull ZoneId getJvmTimeZone()
@Nonnull Optional<ZoneId> getServerTimeZone()
Return the configured server time zone.
@Nonnull Optional<ZoneId> getUserTimeZone()
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.
[Expand]
Inherited Methods
From interface com.atlassian.bitbucket.timezone.UserTimeZoneSupplier

Public Methods

@Nonnull public ZoneId 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.

@Nonnull public ZoneId getJvmTimeZone ()

Returns
  • the time zone configured for the JVM.

@Nonnull public Optional<ZoneId> getServerTimeZone ()

Return the configured server time zone. empty() will be returned if no server time zone is configured.

Returns
  • the configured server time zone.

@Nonnull public Optional<ZoneId> getUserTimeZone ()

Return the time zone the current user has explicitly configured. This method will return empty() when no time zone is configured.

NOTE: Use getTimeZone() when looking up the time zone that is applicable to the current user (e.g. when rendering dates). The getTimeZone 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 empty() if there is none.

public void setServerTimeZone (ZoneId zone)

Set the server time zone. null may be passed to clear the setting.

Parameters
zone the zone of configure or null to clear the setting.

public void setUserTimeZone (ZoneId zone)

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 anonymously
IllegalUserStateException if the context user type does not support setting a time zone.