Class TimezoneResolverServiceImpl
java.lang.Object
ch.tocco.nice2.toolbox.impl.timezone.TimezoneResolverServiceImpl
- All Implemented Interfaces:
TimezoneResolverService
@Component
public class TimezoneResolverServiceImpl
extends Object
implements TimezoneResolverService
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.joda.time.DateTimeZone
getCurrentDateTimeForGuiTimezone
(Locale locale, @Nullable String pattern) org.joda.time.DateTimeZone
Returns the project-specific default timezone id.@Nullable org.joda.time.DateTimeZone
@Nullable String
Returns the gui timezone id for the current user to be used in the gui right now.void
void
setDefaultTimezone
(String defaultTimezone) void
setTimezoneResolver
(List<TimezoneResolver> timezoneResolver) withBestTimezone
(org.joda.time.DateTimeZone dateTimeZone) Use a specifiedDateTimeZone
as 'best' timezone (i.e.Use the system's default timezone (i.e.
-
Constructor Details
-
TimezoneResolverServiceImpl
public TimezoneResolverServiceImpl(org.slf4j.Logger log)
-
-
Method Details
-
initialize
@PostConstruct public void initialize() -
getDefaultTimezoneId
Description copied from interface:TimezoneResolverService
Returns the project-specific default timezone id.- Specified by:
getDefaultTimezoneId
in interfaceTimezoneResolverService
- Returns:
- olson-tz name.
-
getTimezoneIdForGui
Description copied from interface:TimezoneResolverService
Returns the gui timezone id for the current user to be used in the gui right now.- Specified by:
getTimezoneIdForGui
in interfaceTimezoneResolverService
- Returns:
- olson-tz name, or
null
if unknown.
-
getBestTimezoneId
- Specified by:
getBestTimezoneId
in interfaceTimezoneResolverService
- Returns:
- the id of the
user's timezone
if available, falls back to the id of theproject's default timezone
.
-
getDefaultTimeZone
public org.joda.time.DateTimeZone getDefaultTimeZone()- Specified by:
getDefaultTimeZone
in interfaceTimezoneResolverService
- Returns:
- the project-specific default timezone
-
getBestTimezone
public org.joda.time.DateTimeZone getBestTimezone()- Specified by:
getBestTimezone
in interfaceTimezoneResolverService
- Returns:
- the
user's timezone
if available, falls back to theproject's default timezone
-
getTimezoneForGui
@Nullable public @Nullable org.joda.time.DateTimeZone getTimezoneForGui()- Specified by:
getTimezoneForGui
in interfaceTimezoneResolverService
- Returns:
- returns the gui timezone for the current user
-
getCurrentDateTimeForGuiTimezone
- Specified by:
getCurrentDateTimeForGuiTimezone
in interfaceTimezoneResolverService
- Parameters:
locale
- the locale to be used for the formatpattern
- an optional pattern, a pattern with style "SS" will be used if null- Returns:
- the current date and time as a formatted string
-
withBestTimezone
Description copied from interface:TimezoneResolverService
Use a specifiedDateTimeZone
as 'best' timezone (i.e. the timezone returned byTimezoneResolverService.getBestTimezone()
instead of whatever was potentially set on the current request. Note: this does not influence calls toTimezoneResolverService.getTimezoneForGui()
, as this will still return the timezone as set by the current request.- Specified by:
withBestTimezone
in interfaceTimezoneResolverService
- Parameters:
dateTimeZone
- the timezone to be used- Returns:
- an invoker with the best timezone set to the specified timezone
-
withDefaultAsBestTimezone
Description copied from interface:TimezoneResolverService
Use the system's default timezone (i.e. the timezone returned byTimezoneResolverService.getBestTimezone()
) as 'best' timezone (i.e. the timezone returned byTimezoneResolverService.getBestTimezone()
instead of whatever was potentially set on the current request. Note: this does not influence calls toTimezoneResolverService.getTimezoneForGui()
, as this will still return the timezone as set by the current request.- Specified by:
withDefaultAsBestTimezone
in interfaceTimezoneResolverService
- Returns:
- an invoker with the best timezone set to the system's default timezone
-
setDefaultTimezone
- Parameters:
defaultTimezone
- The timezone from the application.properties, eg "America/New_York".
-
setTimezoneResolver
-