/** * This function retrieves a duration in seconds that depends on number of hours in a day and * days in a week. The default unit is MINUTE (i.e. "2" == "2 minutes") * * @param durationStr to convert to a duration * @param hoursPerDay Number of hourse i day * @param daysPerWeek Days Per Week * @return the duration in seconds * @throws InvalidDurationException if its badly formatted duration */ public static long getDuration(String durationStr, int hoursPerDay, int daysPerWeek) throws InvalidDurationException { return getDuration(durationStr, hoursPerDay, daysPerWeek, Duration.MINUTE); }
/** * Check whether a given duration string is valid * * @param s the duration string * @return true if it a valid duration */ public static boolean validDuration(String s) { try { getDuration(s); return true; } catch (InvalidDurationException e) { return false; } }
/** * This function retrieves a duration in seconds that depends on number of hours in a day and * days in a week. The default unit is MINUTE (i.e. "2" == "2 minutes") * * @param durationStr to convert to a duration * @param hoursPerDay Number of hourse i day * @param daysPerWeek Days Per Week * @return the duration in seconds * @throws InvalidDurationException if its badly formatted duration */ public static long getDuration(String durationStr, int hoursPerDay, int daysPerWeek) throws InvalidDurationException { return getDuration(durationStr, hoursPerDay, daysPerWeek, Duration.MINUTE); }
/** * Check whether a given duration string is valid * * @param s the duration string * @return true if it a valid duration */ public static boolean validDuration(String s) { try { getDuration(s); return true; } catch (InvalidDurationException e) { return false; } }
/** * 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> * If no category is specified, assume minutes.<br> * Each field must be separated by a space, and they can come in any order. * Case is ignored. * <p/> * ie 2h = 7200, 60m = 3600, 3d = 259200, 30m * * @param durationStr the duration string * @return the duration in seconds * @throws InvalidDurationException if the duration is invalid */ public static long getDuration(String durationStr) throws InvalidDurationException { return getDuration(durationStr, 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> * If no category is specified, assume minutes.<br> * Each field must be separated by a space, and they can come in any order. * Case is ignored. * <p/> * ie 2h = 7200, 60m = 3600, 3d = 259200, 30m * * @param durationStr the duration string * @return the duration in seconds * @throws InvalidDurationException if the duration is invalid */ public static long getDuration(String durationStr) throws InvalidDurationException { return getDuration(durationStr, Duration.MINUTE); }
private Date parseDate(String span) { try { long time = DateUtils.getDuration(span) * DateUtils.SECOND_MILLIS; return new Date(System.currentTimeMillis() - time); } catch (InvalidDurationException e) { // must be a specified date try { return timespanDF.parse(span); } catch (ParseException e1) { return null; } } }
/** * Get a duration string with the possibility of a negative. * <p/> * A duration will be considered negative if the first non-space character is a - sign. * * @param durationStr the duration string * @return the duration in seconds, which can be negative * @throws InvalidDurationException if its a badly formatted duration */ public static long getDurationWithNegative(String durationStr) throws InvalidDurationException { String cleanedDurationStr = (durationStr != null ? durationStr.trim() : ""); if (cleanedDurationStr.isEmpty()) { return 0; } boolean negative = false; if (cleanedDurationStr.charAt(0) == '-') { negative = true; } if (negative) { return 0 - getDuration(cleanedDurationStr.substring(1)); } else { return getDuration(cleanedDurationStr); } }
/** * Get a duration string with the possibility of a negative. * <p/> * A duration will be considered negative if the first non-space character is a - sign. * * @param durationStr the duration string * @return the duration in seconds, which can be negative * @throws InvalidDurationException if its a badly formatted duration */ public static long getDurationWithNegative(String durationStr) throws InvalidDurationException { if (StringUtils.isEmpty(durationStr)) { return 0; } durationStr = durationStr.trim(); boolean negative = false; if (durationStr.charAt(0) == '-') { negative = true; } if (negative) { return 0 - getDuration(durationStr.substring(1)); } else { return getDuration(durationStr); } }
try duration = DateUtils.getDuration(period); return createQuery(new Date(new Date().getTime() - duration * 1000), new Date());
long duration = DateUtils.getDuration(lastModified); final Date currentDateLessDuration = getCurrentDateLessDuration(duration); DateRangeQuery.DateRange dateRange = new DateRangeQuery.DateRange(currentDateLessDuration, null, true, false);
try { long duration = DateUtils.getDuration(time);