Package com.atlassian.jira.util
Class JiraDurationUtils
java.lang.Object
com.atlassian.jira.util.JiraDurationUtils
Util class responsible for printing durations in various formats.
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This formatter formats time duration to days only.static interface
This interface defines methods for formatting time durationstatic class
This formatter formats time duration to hours only.static class
This formatter formats time duration to "pretty" format, such as 3 weeks, 2 days, 1 hour, 15 minutes. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DurationFormatterProvider
duration formatter currently in usestatic final String
days formatter application property valuestatic final String
hours formatter application property valuestatic final String
pretty formatter aplication property value -
Constructor Summary
ConstructorsConstructorDescriptionJiraDurationUtils
(TimeTrackingConfiguration timeTrackingConfiguration, DurationFormatterProvider durationFormatterProvider, com.atlassian.event.api.EventPublisher eventPublisher) 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) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptiongetFormattedDuration
(Long duration) Formats time duration with default (system) localegetFormattedDuration
(Long duration, Locale locale) Formats time duration with given localeReturns i18n resource key for the current formattergetShortFormattedDuration
(Long duration) Formats time duration in the most compact way possible.getShortFormattedDuration
(Long duration, Locale locale) Formats time duration in the most compact way possible.parseDuration
(String duration) Deprecated.since v4.4.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
updateFormatters
(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext) Deprecated.UseDurationFormatChanged
instead.
-
Field Details
-
FORMAT_PRETTY
pretty formatter aplication property value- See Also:
-
FORMAT_HOURS
hours formatter application property value- See Also:
-
FORMAT_DAYS
days formatter application property value- See Also:
-
durationFormatterProvider
duration formatter currently in use
-
-
Constructor Details
-
JiraDurationUtils
@Deprecated public JiraDurationUtils(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext, TimeTrackingConfiguration timeTrackingConfiguration, com.atlassian.event.api.EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory) Deprecated.UseJiraDurationUtils(TimeTrackingConfiguration, DurationFormatterProvider, EventPublisher)
instead. Since v6.2.Sets the duration formatter based on the settings in the application properties and authentication context- Parameters:
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.
-
JiraDurationUtils
@Deprecated public JiraDurationUtils(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext, TimeTrackingConfiguration timeTrackingConfiguration, com.atlassian.event.api.EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory, com.atlassian.cache.CacheManager cacheManager) Deprecated.UseJiraDurationUtils(TimeTrackingConfiguration, DurationFormatterProvider, EventPublisher)
instead. Since v7.2.Sets the duration formatter based on the settings in the application properties and authentication context- Parameters:
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 manager- Since:
- v6.2
-
JiraDurationUtils
public JiraDurationUtils(TimeTrackingConfiguration timeTrackingConfiguration, DurationFormatterProvider durationFormatterProvider, com.atlassian.event.api.EventPublisher eventPublisher) - Parameters:
timeTrackingConfiguration
- the current time tracking configurationdurationFormatterProvider
- the duration formatter factory- Since:
- v7.2
-
-
Method Details
-
updateFormatters
@Deprecated public void updateFormatters(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext) Deprecated.UseDurationFormatChanged
instead. Since 7.2.Sets the duration formatter with a new instance of a particular formatter chosen based on the settings in the application properties and authentication context.- Parameters:
applicationProperties
- application propertiesauthenticationContext
- authentication context
-
getI18nKey
Returns i18n resource key for the current formatter- Returns:
- i18n resource key
-
getFormattedDuration
Formats time duration with default (system) locale- Parameters:
duration
- time duration to format- Returns:
- formatted time duration
-
getFormattedDuration
Formats time duration with given locale- Parameters:
duration
- time duration to formatlocale
- user's locale- Returns:
- formatted time duration
-
getShortFormattedDuration
Formats time duration in the most compact way possible.- Parameters:
duration
- time duration to format- Returns:
- formatted time duration
-
getShortFormattedDuration
Formats time duration in the most compact way possible.- Parameters:
duration
- time in secondslocale
- locale to use. This is used only for translation, not for decimal formatting.- Returns:
- formatted time duration
-
parseDuration
public Long parseDuration(String duration, Locale locale) throws com.atlassian.core.util.InvalidDurationException Turn a duration string into the number of seconds that it represents, taking into account JIRA's configuration (i.e. how many hours are in a day, how many days are in a week, etc)- Parameters:
duration
- string in JIRA's duration format (i.e. "20h")locale
- Locale to use when interpreting the duration string- Returns:
- number of seconds in the duration string
- Throws:
com.atlassian.core.util.InvalidDurationException
- when the duration cannot be parsed
-
parseDuration
Deprecated.since v4.4. UseparseDuration(String location, Locale locale)
instead.Turn a duration string into the number of seconds that it represents, taking into account JIRA's configuration (i.e. how many hours are in a day, how many days are in a week, etc)This uses the default locale of Locale.UK and is retained for backwards compatibility
- Parameters:
duration
- string in JIRA's duration format (i.e. "20h")- Returns:
- number of seconds in the duration string
- Throws:
com.atlassian.core.util.InvalidDurationException
- when the duration cannot be parsed
-
JiraDurationUtils(TimeTrackingConfiguration, DurationFormatterProvider, EventPublisher)
instead.