if (numSecs >= Duration.HOUR.getSeconds()) long hours = numSecs / Duration.HOUR.getSeconds(); result.append(hours).append(' '); numSecs = numSecs % Duration.HOUR.getSeconds(); if (numSecs >= Duration.MINUTE.getSeconds()) long minute = numSecs / Duration.MINUTE.getSeconds(); result.append(minute).append(' '); numSecs = numSecs % Duration.MINUTE.getSeconds(); if (numSecs >= 1 && numSecs < Duration.MINUTE.getSeconds())
months = difference / Duration.MONTH.getMilliseconds(); if (months > 0) difference = difference % Duration.MONTH.getMilliseconds(); if (months > 1) days = difference / Duration.DAY.getMilliseconds(); if (days > 0) difference = difference % Duration.DAY.getMilliseconds(); if (days > 1) hours = difference / Duration.HOUR.getMilliseconds(); if (hours > 0) difference = difference % Duration.HOUR.getMilliseconds(); if (hours > 1) minutes = difference / Duration.MINUTE.getMilliseconds(); if (minutes > 0) difference = difference % Duration.MINUTE.getMilliseconds(); if (minutes > 1) seconds = difference / Duration.SECOND.getMilliseconds(); if (seconds > 0)
private static String validateDurationUnit(final String durationString, final Duration duration) throws InvalidDurationException { if (durationString.length() > 1) { String singular = duration.name().toLowerCase(); String plural = duration.name().toLowerCase() + "s"; if (durationString.contains(plural)) { return durationString.substring(durationString.indexOf(plural)); } else if (durationString.contains(singular)) { return durationString.substring(durationString.indexOf(singular)); } else { throw new InvalidDurationException("Not a valid durationString string"); } } return durationString.substring(1); }
months = difference / Duration.MONTH.getMilliseconds(); if (months > 0) { difference = difference % Duration.MONTH.getMilliseconds(); if (months > 1) { sb.append(months).append(" ").append(getText(resourceBundle, "core.dateutils.months")).append(", "); days = difference / Duration.DAY.getMilliseconds(); if (days > 0) { difference = difference % Duration.DAY.getMilliseconds(); if (days > 1) { sb.append(days).append(" ").append(getText(resourceBundle, "core.dateutils.days")).append(", "); hours = difference / Duration.HOUR.getMilliseconds(); if (hours > 0) { difference = difference % Duration.HOUR.getMilliseconds(); if (hours > 1) { sb.append(hours).append(" ").append(getText(resourceBundle, "core.dateutils.hours")).append(", "); minutes = difference / Duration.MINUTE.getMilliseconds(); if (minutes > 0) { difference = difference % Duration.MINUTE.getMilliseconds(); if (minutes > 1) { sb.append(minutes).append(" ").append(getText(resourceBundle, "core.dateutils.minutes")).append(", "); seconds = difference / Duration.SECOND.getMilliseconds(); if (seconds > 0) { if (seconds > 1) {
if (numSecs >= Duration.HOUR.getSeconds()) { long hours = numSecs / Duration.HOUR.getSeconds(); result.append(hours).append(' '); numSecs = numSecs % Duration.HOUR.getSeconds(); if (numSecs >= Duration.MINUTE.getSeconds()) { long minute = numSecs / Duration.MINUTE.getSeconds(); result.append(minute).append(' '); numSecs = numSecs % Duration.MINUTE.getSeconds(); if (numSecs >= 1 && numSecs < Duration.MINUTE.getSeconds()) { result.append(numSecs).append(' ');
time = Long.parseLong(durationStr.trim()) * defaultUnit.getSeconds(); time *= Duration.MINUTE.getSeconds(); break; case(int) 'h': remainingDurationStr = validateDurationUnit(durationStr.substring(i), "hours"); time *= Duration.HOUR.getSeconds(); break; case(int) 'd':
try // detect if we just have a number time = Long.parseLong(durationStr.trim()) * defaultUnit.getModifiedSeconds(secondsPerDay, secondsPerWeek); } catch (Exception ex) // otherwise get the value
long s = (long) (unit.getModifiedSeconds(secondsPerDay, secondsPerWeek) * n.doubleValue());
if (l >= Duration.HOUR.getSeconds()) { result.append((l / Duration.HOUR.getSeconds())); result.append("h "); l = l % Duration.HOUR.getSeconds(); if (l >= Duration.MINUTE.getSeconds()) { result.append((l / Duration.MINUTE.getSeconds())); result.append("m ");
case (int) 'm': validateDurationUnit(unit.substring(0), Duration.MINUTE); time = Duration.MINUTE.getSeconds(); break; case (int) 'h': validateDurationUnit(unit.substring(0), Duration.HOUR); time = Duration.HOUR.getSeconds(); break; case (int) 'd':
final TimeFormatWithPrecision result = calculateFractionalTimeUnit(duration, hoursPerDay.multiply(BigDecimal.valueOf(DateUtils.Duration.HOUR.getSeconds())).intValueExact(), i18nBean, UNIT_DAY, scale, userLocale); if (result.remainder == 0)
if (l >= Duration.HOUR.getSeconds()) result.append((l / Duration.HOUR.getSeconds())); result.append("h "); l = l % Duration.HOUR.getSeconds(); if (l >= Duration.MINUTE.getSeconds()) result.append((l / Duration.MINUTE.getSeconds())); result.append("m ");
final TimeFormatWithPrecision result = calculateFractionalTimeUnit(duration, (int) DateUtils.Duration.HOUR.getSeconds(), i18nBean, UNIT_HOUR, scale, userLocale); if (result.remainder == 0) return calculateFractionalTimeUnit(result.remainder, (int) DateUtils.Duration.MINUTE.getSeconds(), i18nBean, UNIT_MINUTE, scale, userLocale).formatted; return result.formatted + ' ' + calculateFractionalTimeUnit(result.remainder, (int) DateUtils.Duration.MINUTE.getSeconds(), i18nBean, UNIT_MINUTE, scale, userLocale).formatted;
public String doDefault() throws Exception { // Retrieve the worklog worklog = worklogService.getById(getJiraServiceContext(), getWorklogId()); if (worklog == null) { addErrorMessage(getText("logwork.error.update.invalid.id", (getWorklogId() == null) ? null : getWorklogId().toString())); return ERROR; } if (!worklogService.hasPermissionToUpdate(getJiraServiceContext(), worklog)) { //user doesn't have permission to run this action return "securitybreach"; } //pre-populate the fields final BigDecimal hoursPerDay = getHoursPerDay(); final BigDecimal daysPerWeek = getDaysPerWeek(); final BigDecimal secondsPerHour = BigDecimal.valueOf(DateUtils.Duration.HOUR.getSeconds()); final long secondsPerDay = hoursPerDay.multiply(secondsPerHour).longValueExact(); final long secondsPerWeek = daysPerWeek.multiply(hoursPerDay).multiply(secondsPerHour).longValueExact(); setTimeLogged(DateUtils.getDurationStringSeconds(worklog.getTimeSpent(), secondsPerDay, secondsPerWeek)); setStartDate(getFormattedStartDate(worklog.getStartDate())); setComment(worklog.getComment()); setCommentLevel(CommentVisibility.getCommentLevelFromLevels(worklog.getGroupLevel(), worklog.getRoleLevelId())); return super.doDefault(); }
public TimeTrackingAdmin(final ApplicationProperties applicationProperties, final FieldManager fieldManager, final JiraDurationUtils jiraDurationUtils, final JiraAuthenticationContext authenticationContext, final PluginAccessor pluginAccessor, final ReindexMessageManager reindexMessageManager, final FeatureManager featureManager) { this.applicationProperties = applicationProperties; this.fieldManager = fieldManager; this.jiraDurationUtils = jiraDurationUtils; this.authenticationContext = authenticationContext; this.pluginAccessor = pluginAccessor; this.reindexMessageManager = notNull("reindexMessageManager", reindexMessageManager); this.featureManager = featureManager; hoursPerDay = applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_HOURS_PER_DAY); daysPerWeek = applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_DAYS_PER_WEEK); timeTrackingFormat = applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_FORMAT); try { defaultUnit = DateUtils.Duration.valueOf(applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_DEFAULT_UNIT)); } catch (IllegalArgumentException e) { defaultUnit = DateUtils.Duration.MINUTE; } catch (NullPointerException e) { defaultUnit = DateUtils.Duration.MINUTE; } }
/** * Given a duration string, get the number of seconds it represents (all case insensitive): * <ul> * <li>w = weeks * <li>d = days * <li>h = hours * <li>m = minutes * </ul> * ie 2h = 7200, 60m = 3600, 3d = 259200, 30m * * @param durationStr the duration string * @param defaultUnit the unit used when another is not specified in the durationStr * @return the duration in seconds * @throws InvalidDurationException if the duration is invalid */ public static long getDuration(final String durationStr, final Duration defaultUnit) throws InvalidDurationException { return getDurationSeconds(durationStr, Duration.DAY.getSeconds(), Duration.WEEK.getSeconds(), defaultUnit); }
/** * 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) * * @param duration string in JIRA's duration format (i.e. "20h") * @param locale Locale to use when interpreting the duration string * @return number of seconds in the duration string * @throws InvalidDurationException when the duration cannot be parsed */ public Long parseDuration(final String duration, Locale locale) throws InvalidDurationException { //Retrieve the number of hours per day and number of days per week final BigDecimal hoursPerDay = timeTrackingConfiguration.getHoursPerDay(); final BigDecimal daysPerWeek = timeTrackingConfiguration.getDaysPerWeek(); final BigDecimal secondsPerHour = BigDecimal.valueOf(DateUtils.Duration.HOUR.getSeconds()); final long secondsPerDay = hoursPerDay.multiply(secondsPerHour).longValueExact(); final long secondsPerWeek = daysPerWeek.multiply(hoursPerDay).multiply(secondsPerHour).longValueExact(); return DurationUtils.getDurationSeconds(duration, secondsPerDay, secondsPerWeek, timeTrackingConfiguration.getDefaultUnit(), locale, TOKEN_MAP); }
public String getDefaultTimeUnit() { final Map<String, String> map = MapBuilder.<String, String>newBuilder() .add(DateUtils.Duration.MINUTE.name(), getText("core.dateutils.minute")) .add(DateUtils.Duration.HOUR.name(), getText("core.dateutils.hour")) .add(DateUtils.Duration.DAY.name(), getText("core.dateutils.day")) .add(DateUtils.Duration.WEEK.name(), getText("core.dateutils.week")).toMap(); DateUtils.Duration defaultUnit; try { defaultUnit = DateUtils.Duration.valueOf(applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_DEFAULT_UNIT)); } catch (IllegalArgumentException e) { defaultUnit = DateUtils.Duration.MINUTE; } catch (NullPointerException e) { defaultUnit = DateUtils.Duration.MINUTE; } return map.get(defaultUnit.toString()); }
/** * Given a duration string, get the number of seconds it represents (all case insensitive): * <ul> * <li>w = weeks * <li>d = days * <li>h = hours * <li>m = minutes * </ul> * ie 2h = 7200, 60m = 3600, 3d = 259200, 30m * * @param durationStr the duration string * @param defaultUnit the unit used when another is not specified in the durationStr * @return the duration in seconds * @throws InvalidDurationException if the duration is invalid */ public static long getDuration(final String durationStr, final Duration defaultUnit) throws InvalidDurationException { return getDurationSeconds(durationStr, Duration.DAY.getSeconds(), Duration.WEEK.getSeconds(), defaultUnit); }
/** * Converts a number of seconds into a pretty formatted data string. The resolution is in minutes. So if the number of seconds is greater than a minute, it will * only be shown down top minute resolution. If the number of seconds is less than a minute it will be shown in seconds. * <p/> * So for example <code>76</code> becomes <code>'1 minute'</code>, while <code>42</code> becomes <code>'42 seconds'</code> * * @param numSecs the number of seconds in the duration * @param hoursPerDay the hours in a day * @param daysPerWeek the number of days in a week * @param resourceBundle a resouce bundle for i18n * @return a string in readable pretty duration format, using minute resolution */ public static String getDurationPretty(long numSecs, int hoursPerDay, int daysPerWeek, ResourceBundle resourceBundle) { long secondsInDay = hoursPerDay * Duration.HOUR.getSeconds(); long secondsPerWeek = daysPerWeek * secondsInDay; return getDurationPrettySeconds(numSecs, secondsInDay, secondsPerWeek, resourceBundle, false); }