/** * 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 * * @param duration string in JIRA's duration format (i.e. "20h") * @return number of seconds in the duration string * @throws InvalidDurationException when the duration cannot be parsed * @deprecated since v4.4. Use {@link #parseDuration(String location, Locale locale)} instead. */ public Long parseDuration(final String duration) throws InvalidDurationException { return parseDuration(duration, Locale.UK); }
@Override public Long apply(@Nullable String from) { try { return durationUtils.parseDuration(from, Locale.ENGLISH); } catch (InvalidDurationException e) { return null; } catch (NumberFormatException e) { return null; } } }
/** * @param duration the input duration * @return true only if the input duration is not blank and is not valid as deemed by {@link JiraDurationUtils#parseDuration(String, Locale)} */ boolean isDurationInvalid(final String duration) { if (StringUtils.isNotBlank(duration)) { try { jiraDurationUtils.parseDuration(duration, authenticationContext.getLocale()); } catch (InvalidDurationException e) { return true; } } return false; }
private Long convertDurationIntoSeconds(final String estimate) { try { return jiraDurationUtils.parseDuration(estimate, authenticationContext.getLocale()); } catch (InvalidDurationException e) { log.error("Error occurred while converting time estimates."); throw new IllegalArgumentException("Error occurred while converting time estimates:" + e.getMessage()); } }
protected long getDurationForFormattedString(String timeSpent, JiraServiceContext jiraServiceContext) { try { return jiraDurationUtils.parseDuration(timeSpent, jiraServiceContext.getI18nBean().getLocale()); } catch (InvalidDurationException e) { // This should never happen since we have done the validation with isValid before this method is ever // called log.error("Trying to create/update a worklog with an invalid duration, this should never happen.", e); throw new RuntimeException(e); } }
@VisibleForTesting Long convertDurationToMins(final String duration) throws InvalidDurationException { return getJiraDurationUtils().parseDuration(duration, getAuthenticationContext().getLocale()); }
/** * @param duration the input duration * @return true only if the input duration is not blank and is not valid as deemed by {@link com.atlassian.jira.util.JiraDurationUtils#parseDuration(String, java.util.Locale)} */ boolean isValidDuration(final String duration, JiraServiceContext jiraServiceContext) { if (StringUtils.isNotBlank(duration)) { try { jiraDurationUtils.parseDuration(duration, jiraServiceContext.getI18nBean().getLocale()); } catch (InvalidDurationException e) { return false; } } return true; }
@Override public void init(PropertySet props) throws ObjectConfigurationException { super.init(props); if (hasProperty(RETENTION_PERIOD)) { String retention = getProperty(RETENTION_PERIOD); try { retentionPeriod = jiraDurationUtils.parseDuration(retention, jiraAuthenticationContext.getLocale()); } catch (InvalidDurationException e) { LOGGER.error("Invalid Duration specified in service configuration", e); } } }
@Override public void init(PropertySet props) throws ObjectConfigurationException { super.init(props); if (hasProperty(RETENTION_PERIOD)) { String retention = getProperty(RETENTION_PERIOD); try { retentionPeriod = jiraDurationUtils.parseDuration(retention, jiraAuthenticationContext.getLocale()); } catch (InvalidDurationException e) { LOGGER.error("Invalid Duration specified in service configuration", e); } } }