public class JiraDurationUtils extends Object implements Startable
Note that this class uses the Duration
formatting as configured for time-tracking and is therefore quite specific. For more generic duration formatting see
DateUtils
Modifier and Type | Class and Description |
---|---|
static class |
JiraDurationUtils.DaysDurationFormatter
This formatter formats time duration to days only.
|
static interface |
JiraDurationUtils.DurationFormatter
This interface defines methods for formatting time duration
|
static class |
JiraDurationUtils.HoursDurationFormatter
This formatter formats time duration to hours only.
|
static class |
JiraDurationUtils.PrettyDurationFormatter
This formatter formats time duration to "pretty" format, such as 3 weeks, 2 days, 1 hour, 15 minutes.
|
Modifier and Type | Field and Description |
---|---|
static String |
FORMAT_DAYS
days formatter application property value
|
static String |
FORMAT_HOURS
hours formatter application property value
|
static String |
FORMAT_PRETTY
pretty formatter aplication property value
|
protected com.atlassian.cache.CachedReference<JiraDurationUtils.DurationFormatter> |
formatterRef
duration formatter currently in use
|
Constructor and Description |
---|
JiraDurationUtils(ApplicationProperties applicationProperties,
JiraAuthenticationContext authenticationContext,
TimeTrackingConfiguration timeTrackingConfiguration,
com.atlassian.event.api.EventPublisher eventPublisher,
I18nHelper.BeanFactory i18nFactory)
Deprecated.
|
JiraDurationUtils(ApplicationProperties applicationProperties,
JiraAuthenticationContext authenticationContext,
TimeTrackingConfiguration timeTrackingConfiguration,
com.atlassian.event.api.EventPublisher eventPublisher,
I18nHelper.BeanFactory i18nFactory,
com.atlassian.cache.CacheManager cacheManager)
Sets the duration formatter based on the settings in the application properties and authentication context
|
Modifier and Type | Method and Description |
---|---|
String |
getFormattedDuration(Long duration)
Formats time duration with default (system) locale
|
String |
getFormattedDuration(Long duration,
Locale locale)
Formats time duration with given locale
|
String |
getI18nKey()
Returns i18n resource key for the current formatter
|
String |
getShortFormattedDuration(Long duration)
Formats time duration in the most compact way possible.
|
String |
getShortFormattedDuration(Long duration,
Locale locale)
Formats time duration in the most compact way possible.
|
void |
onClearCache(ClearCacheEvent event) |
Long |
parseDuration(String duration)
Deprecated.
since v4.4. Use
parseDuration(String location, Locale locale) instead. |
Long |
parseDuration(String duration,
Locale locale)
Turn a duration string into the number of seconds that it represents, taking into account JIRA's configuration
(i.e.
|
void |
start()
This method will be called after the plugin system is fully initialised and all components added to the
dependency injection framework.
|
void |
updateFormatters(ApplicationProperties applicationProperties,
JiraAuthenticationContext authenticationContext)
Sets the duration formatter with a new instance of a particular formatter chosen based on the settings in the
application properties and authentication context
|
public static final String FORMAT_PRETTY
public static final String FORMAT_HOURS
public static final String FORMAT_DAYS
protected com.atlassian.cache.CachedReference<JiraDurationUtils.DurationFormatter> formatterRef
public JiraDurationUtils(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext, TimeTrackingConfiguration timeTrackingConfiguration, com.atlassian.event.api.EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory)
JiraDurationUtils(ApplicationProperties, JiraAuthenticationContext, TimeTrackingConfiguration, EventPublisher, I18nHelper.BeanFactory, CacheManager)
applicationProperties
- application propertiesauthenticationContext
- the context of the logged in user, used to get an I18nHelper appropriate for the
usertimeTrackingConfiguration
- the current time tracking configurationeventPublisher
- event publisher so the duration utils can be notified when an import occurs.i18nFactory
- the creator of i18nBean classes.public JiraDurationUtils(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext, TimeTrackingConfiguration timeTrackingConfiguration, com.atlassian.event.api.EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory, com.atlassian.cache.CacheManager cacheManager)
applicationProperties
- application propertiesauthenticationContext
- the context of the logged in user, used to get an I18nHelper appropriate for the
usertimeTrackingConfiguration
- the current time tracking configurationeventPublisher
- event publisher so the duration utils can be notified when an import occurs.i18nFactory
- the creator of i18nBean classes.cacheManager
- the cache managerpublic void start() throws Exception
Startable
@EventListener public void onClearCache(ClearCacheEvent event)
public void updateFormatters(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext)
applicationProperties
- application propertiesauthenticationContext
- authentication contextpublic String getI18nKey()
public String getFormattedDuration(Long duration)
duration
- time duration to formatpublic String getFormattedDuration(Long duration, Locale locale)
duration
- time duration to formatlocale
- user's localepublic String getShortFormattedDuration(Long duration)
duration
- time duration to formatpublic String getShortFormattedDuration(Long duration, Locale locale)
duration
- time in secondslocale
- locale to use. This is used only for translation, not for decimal formatting.public Long parseDuration(String duration, Locale locale) throws com.atlassian.core.util.InvalidDurationException
duration
- string in JIRA's duration format (i.e. "20h")locale
- Locale to use when interpreting the duration stringcom.atlassian.core.util.InvalidDurationException
- when the duration cannot be parsedpublic Long parseDuration(String duration) throws com.atlassian.core.util.InvalidDurationException
parseDuration(String location, Locale locale)
instead.This uses the default locale of Locale.UK and is retained for backwards compatibility
duration
- string in JIRA's duration format (i.e. "20h")com.atlassian.core.util.InvalidDurationException
- when the duration cannot be parsedCopyright © 2002-2016 Atlassian. All Rights Reserved.