/** * Parse milliseconds from a time string that ends with a unit of measure. If no unit of measure is provided, milliseconds is assumed. Unit of measure is case insensitive. * * <pre> * 1 == 1 millisecond * 1ms == 1 millisecond * 1s == 1 second == 1000 milliseconds * 1m == 1 minute == 60,000 milliseconds * 1h == 1 hour == 3,600,000 milliseconds * 1d == 1 day == 86,400,000 milliseconds * 1y == 1 year == 31,536,000,000 milliseconds * </pre> */ public static long getMillis(String time) { return getMillis(time, TIME_TOKENS, TIME_MULTIPLIERS); }
/** * Parse milliseconds from a time string that ends with a unit of measure. If no unit of measure is provided, milliseconds is assumed. Unit of measure is case insensitive. * * @see FormatUtils.getMillis(String time) */ public static long getMillis(EnvironmentService env, String key, String defaultValue) { String value = env.getString(key, defaultValue); return FormatUtils.getMillis(value); }
/** * Parse milliseconds from a time string that ends with a unit of measure. If no unit of measure is provided, milliseconds is assumed. Unit of measure is case insensitive. * * @see FormatUtils.getMillis(String time) */ public static long getMillis(Environment env, String key, String defaultValue) { String value = getProperty(env, key, defaultValue); return FormatUtils.getMillis(value); }
/** * Sleep for {@code time} where time is in the format 15ms, 15s, 15m, 15h, 15d, 15y for 15 milliseconds, seconds, minutes, hours, days, and years, respectively. Note that years * is approximate as the logic always assumes exactly 365 days a year. * * @throws <code>IllegalStateException</code> if interrupted. */ public static long sleep(String time) { return sleep(getMillis(time)); }
@Override public Long getObject() { Assert.hasText(time, "time has no text"); return FormatUtils.getMillis(time); }
/** * Parse milliseconds from a time string that ends with a unit of measure. If no unit of measure is provided, milliseconds is assumed. Unit of measure is case insensitive. * * <pre> * 1 == 1 millisecond * 1ms == 1 millisecond * 1s == 1 second == 1000 milliseconds * 1m == 1 minute == 60,000 milliseconds * 1h == 1 hour == 3,600,000 milliseconds * 1d == 1 day == 86,400,000 milliseconds * 1y == 1 year == 31,536,000,000 milliseconds * </pre> */ public static int getMillisAsInt(String time) { Long millis = getMillis(time); if (millis <= Integer.MAX_VALUE) { return millis.intValue(); } else { throw Exceptions.illegalArgument("[%s] converts to [%s]. maximum allowable integer value is [%s]", time, millis, Integer.MAX_VALUE); } }