/** * This function retrieves a duration in seconds that depends on number of hours in a day and * days in a week * * @param durationStr to convert to a duration * @param hoursPerDay Number of hourse i day * @param daysPerWeek Days Per Week * @param defaultUnit the unit used when one is not specified on a measure in the durationStr * @return the duration in seconds * @throws InvalidDurationException if its badly formatted duration */ public static long getDuration(String durationStr, int hoursPerDay, int daysPerWeek, final Duration defaultUnit) throws InvalidDurationException { long secondsInDay = hoursPerDay * Duration.HOUR.getSeconds(); long secondsPerWeek = daysPerWeek * secondsInDay; return getDurationSeconds(durationStr, secondsInDay, secondsPerWeek, defaultUnit); }
/** * This function retrieves a duration in seconds that depends on number of hours in a day and * days in a week * * @param durationStr to convert to a duration * @param hoursPerDay Number of hourse i day * @param daysPerWeek Days Per Week * @param defaultUnit the unit used when one is not specified on a measure in the durationStr * @return the duration in seconds * @throws InvalidDurationException if its badly formatted duration */ public static long getDuration(String durationStr, int hoursPerDay, int daysPerWeek, final Duration defaultUnit) throws InvalidDurationException { long secondsInDay = hoursPerDay * Duration.HOUR.getSeconds(); long secondsPerWeek = daysPerWeek * secondsInDay; return getDurationSeconds(durationStr, secondsInDay, secondsPerWeek, defaultUnit); }
/** * 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); }
/** * 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); }
StringTokenizer st = new StringTokenizer(durationStr, ", "); while (st.hasMoreTokens()) { time += getDurationSeconds(st.nextToken(), secondsPerDay, secondsPerWeek, defaultUnit);
while (st.hasMoreTokens()) time += getDurationSeconds(st.nextToken(), secondsPerDay, secondsPerWeek, defaultUnit); time += getDurationSeconds(remainingDurationStr, secondsPerDay, secondsPerWeek, defaultUnit);