com.atlassian.jira.util
Class JiraDurationUtils

java.lang.Object
  extended by com.atlassian.jira.util.JiraDurationUtils
All Implemented Interfaces:
Startable

public class JiraDurationUtils
extends Object
implements Startable

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 DateUtils


Nested Class Summary
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.
 
Field Summary
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.util.concurrent.ResettableLazyReference<JiraDurationUtils.DurationFormatter> formatterRef
          duration formatter currently in use
 
Constructor Summary
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
 
Method Summary
 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 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_PRETTY

public static final String FORMAT_PRETTY
pretty formatter aplication property value

See Also:
Constant Field Values

FORMAT_HOURS

public static final String FORMAT_HOURS
hours formatter application property value

See Also:
Constant Field Values

FORMAT_DAYS

public static final String FORMAT_DAYS
days formatter application property value

See Also:
Constant Field Values

formatterRef

protected com.atlassian.util.concurrent.ResettableLazyReference<JiraDurationUtils.DurationFormatter> formatterRef
duration formatter currently in use

Constructor Detail

JiraDurationUtils

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.
Method Detail

start

public void start()
           throws Exception
Description copied from interface: Startable
This method wil be called after the plugin system is fully initialised and all components added to the dependency injection framework.

Specified by:
start in interface Startable
Throws:
Exception - Allows implementations to throw an Exception.

onClearCache

@EventListener
public void onClearCache(ClearCacheEvent event)

updateFormatters

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

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. since v4.4. Use parseDuration(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


Copyright © 2002-2012 Atlassian. All Rights Reserved.