Interface TimeZoneService

All Superinterfaces:
UserTimeZoneSupplier

public interface TimeZoneService extends 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. 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 UserTimeZoneSupplier.getTimeZone() and UserTimeZoneSupplier.getTimeZone(ApplicationUser).

Since:
4.6
See Also:
  • Method Details

    • getDefaultTimeZone

      @Nonnull 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.
    • getJvmTimeZone

      @Nonnull ZoneId getJvmTimeZone()
      Returns:
      the time zone configured for the JVM.
    • getServerTimeZone

      @Nonnull Optional<ZoneId> 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

      @Nonnull Optional<ZoneId> getUserTimeZone()
      Return the time zone the current user has explicitly configured. This method will return Optional.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). 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 Optional.empty() if there is none.
    • setServerTimeZone

      void setServerTimeZone(@Nullable 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.
    • setUserTimeZone

      void setUserTimeZone(@Nullable 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.