Class JiraDurationUtils

java.lang.Object
com.atlassian.jira.util.JiraDurationUtils

public class JiraDurationUtils extends Object
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

  • Field Details

  • Constructor Details

    • JiraDurationUtils

      @Deprecated public JiraDurationUtils(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext, TimeTrackingConfiguration timeTrackingConfiguration, com.atlassian.event.api.EventPublisher eventPublisher, I18nHelper.BeanFactory i18nFactory)
      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.
    • JiraDurationUtils

      @Deprecated public 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
      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
      Since:
      v6.2
    • JiraDurationUtils

      public JiraDurationUtils(TimeTrackingConfiguration timeTrackingConfiguration, DurationFormatterProvider durationFormatterProvider, com.atlassian.event.api.EventPublisher eventPublisher)
      Parameters:
      timeTrackingConfiguration - the current time tracking configuration
      durationFormatterProvider - the duration formatter factory
      Since:
      v7.2
  • Method Details

    • updateFormatters

      @Deprecated public void updateFormatters(ApplicationProperties applicationProperties, JiraAuthenticationContext authenticationContext)
      Deprecated.
      Use DurationFormatChanged 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 properties
      authenticationContext - authentication context
    • getI18nKey

      public String getI18nKey()
      Returns i18n resource key for the current formatter
      Returns:
      i18n resource key
    • getFormattedDuration

      public String getFormattedDuration(Long duration)
      Formats time duration with default (system) locale
      Parameters:
      duration - time duration to format
      Returns:
      formatted time duration
    • getFormattedDuration

      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
    • getShortFormattedDuration

      public String getShortFormattedDuration(Long duration)
      Formats time duration in the most compact way possible.
      Parameters:
      duration - time duration to format
      Returns:
      formatted time duration
    • getShortFormattedDuration

      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
    • 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

      public Long parseDuration(String duration) throws com.atlassian.core.util.InvalidDurationException
      Deprecated.
      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