public class

JiraDurationUtils

extends Object
implements Startable
java.lang.Object
   ↳ com.atlassian.jira.util.JiraDurationUtils

Class Overview

Util class reponsible 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 com.atlassian.core.util.DateUtils

Summary

Nested Classes
class JiraDurationUtils.DaysDurationFormatter This formatter formats time duration to days only. 
interface JiraDurationUtils.DurationFormatter This interface defines methods for formatting time duration  
class JiraDurationUtils.HoursDurationFormatter This formatter formats time duration to hours only. 
class JiraDurationUtils.PrettyDurationFormatter This formatter formats time duration to "pretty" format, such as 3 weeks, 2 days, 1 hour, 15 minutes. 
Constants
String FORMAT_DAYS days formatter application property value
String FORMAT_HOURS hours formatter application property value
String FORMAT_PRETTY pretty formatter aplication property value
Fields
protected CachedReference<JiraDurationUtils.DurationFormatter> formatterRef duration formatter currently in use
Public Constructors
JiraDurationUtils(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext, TimeTrackingConfiguration timeTrackingConfiguration, EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory)
JiraDurationUtils(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext, TimeTrackingConfiguration timeTrackingConfiguration, EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory, CacheManager cacheManager)
Sets the duration formatter based on the settings in the application properties and authentication context
Public Methods
String getFormattedDuration(Long duration, Locale locale)
Formats time duration with given locale
String getFormattedDuration(Long duration)
Formats time duration with default (system) locale
String getI18nKey()
Returns i18n resource key for the current formatter
String getShortFormattedDuration(Long duration, Locale locale)
Formats time duration in the most compact way possible.
String getShortFormattedDuration(Long duration)
Formats time duration in the most compact way possible.
@EventListener void onClearCache(ClearCacheEvent event)
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.
Long parseDuration(String duration)
This method is deprecated. since v4.4. Use parseDuration(String, Locale) instead.
void start()
This method wil 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
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.jira.extension.Startable

Constants

public static final String FORMAT_DAYS

days formatter application property value

Constant Value: "days"

public static final String FORMAT_HOURS

hours formatter application property value

Constant Value: "hours"

public static final String FORMAT_PRETTY

pretty formatter aplication property value

Constant Value: "pretty"

Fields

protected CachedReference<JiraDurationUtils.DurationFormatter> formatterRef

duration formatter currently in use

Public Constructors

public JiraDurationUtils (ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext, TimeTrackingConfiguration timeTrackingConfiguration, EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory)

This constructor is deprecated.
Use alternate constructor JiraDurationUtils(ApplicationProperties, JiraAuthenticationContext, TimeTrackingConfiguration, EventPublisher, I18nHelper.BeanFactory, CacheManager)

Sets the duration formatter based on the settings in the application properties and authentication context

Parameters
applicationProperties application properties
authenticationContext the context of the logged in user, used to get an I18nHelper appropriate for the user
timeTrackingConfiguration the current time tracking configuration
eventPublisher 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, EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory, CacheManager cacheManager)

Sets the duration formatter based on the settings in the application properties and authentication context

Parameters
applicationProperties application properties
authenticationContext the context of the logged in user, used to get an I18nHelper appropriate for the user
timeTrackingConfiguration the current time tracking configuration
eventPublisher event publisher so the duration utils can be notified when an import occurs.
i18nFactory the creator of i18nBean classes.
cacheManager the cache manager

Public Methods

public String getFormattedDuration (Long duration, Locale locale)

Formats time duration with given locale

Parameters
duration time duration to format
locale user's locale
Returns
  • formatted time duration

public String getFormattedDuration (Long duration)

Formats time duration with default (system) locale

Parameters
duration time duration to format
Returns
  • formatted time duration

public String getI18nKey ()

Returns i18n resource key for the current formatter

Returns
  • i18n resource key

public String getShortFormattedDuration (Long duration, Locale locale)

Formats time duration in the most compact way possible.

Parameters
duration time in seconds
locale locale to use. This is used only for translation, not for decimal formatting.
Returns
  • formatted time duration

public String getShortFormattedDuration (Long duration)

Formats time duration in the most compact way possible.

Parameters
duration time duration to format
Returns
  • formatted time duration

@EventListener public void onClearCache (ClearCacheEvent event)

public 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. 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
InvalidDurationException when the duration cannot be parsed

public Long parseDuration (String duration)

This method is deprecated.
since v4.4. Use parseDuration(String, 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
InvalidDurationException when the duration cannot be parsed

public void start ()

This method wil be called after the plugin system is fully initialised and all components added to the dependency injection framework.

Throws
Exception

public 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

Parameters
applicationProperties application properties
authenticationContext authentication context