public class JiraDurationUtils extends Object
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 |
---|---|
protected DurationFormatterProvider |
durationFormatterProvider
duration formatter currently in use
|
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
|
Constructor and Description |
---|
JiraDurationUtils(ApplicationProperties applicationProperties,
JiraAuthenticationContext authenticationContext,
TimeTrackingConfiguration timeTrackingConfiguration,
com.atlassian.event.api.EventPublisher eventPublisher,
I18nHelper.BeanFactory i18nFactory)
Deprecated.
Use
JiraDurationUtils(TimeTrackingConfiguration, DurationFormatterProvider, EventPublisher) instead. Since v6.2. |
JiraDurationUtils(ApplicationProperties applicationProperties,
JiraAuthenticationContext authenticationContext,
TimeTrackingConfiguration timeTrackingConfiguration,
com.atlassian.event.api.EventPublisher eventPublisher,
I18nHelper.BeanFactory i18nFactory,
com.atlassian.cache.CacheManager cacheManager)
Deprecated.
Use
JiraDurationUtils(TimeTrackingConfiguration, DurationFormatterProvider, EventPublisher) instead. Since v7.2. |
JiraDurationUtils(TimeTrackingConfiguration timeTrackingConfiguration,
DurationFormatterProvider durationFormatterProvider,
com.atlassian.event.api.EventPublisher eventPublisher) |
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)
Deprecated.
Use
DurationFormatChanged instead. Since v7.2. |
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()
Deprecated.
Not used anymore. Since v7.2.
|
void |
updateFormatters(ApplicationProperties applicationProperties,
JiraAuthenticationContext authenticationContext)
Deprecated.
Use
DurationFormatChanged instead. Since 7.2. |
public static final String FORMAT_PRETTY
public static final String FORMAT_HOURS
public static final String FORMAT_DAYS
protected final DurationFormatterProvider durationFormatterProvider
@Deprecated public JiraDurationUtils(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext, TimeTrackingConfiguration timeTrackingConfiguration, com.atlassian.event.api.EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory)
JiraDurationUtils(TimeTrackingConfiguration, DurationFormatterProvider, EventPublisher)
instead. Since v6.2.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.@Deprecated public JiraDurationUtils(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext, TimeTrackingConfiguration timeTrackingConfiguration, com.atlassian.event.api.EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory, com.atlassian.cache.CacheManager cacheManager)
JiraDurationUtils(TimeTrackingConfiguration, DurationFormatterProvider, EventPublisher)
instead. Since v7.2.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 JiraDurationUtils(TimeTrackingConfiguration timeTrackingConfiguration, DurationFormatterProvider durationFormatterProvider, com.atlassian.event.api.EventPublisher eventPublisher)
timeTrackingConfiguration
- the current time tracking configurationdurationFormatterProvider
- the duration formatter factory@Deprecated public void start() throws Exception
Startable
anymore, but we need to keep
this method around to avoid breaking binary compatibility.Exception
@Deprecated public void onClearCache(ClearCacheEvent event)
DurationFormatChanged
instead. Since v7.2.JiraDurationUtils.DurationFormatter
any more, but it can't be removed yet as it
would break API.@Deprecated public void updateFormatters(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext)
DurationFormatChanged
instead. Since 7.2.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-2024 Atlassian. All Rights Reserved.