List of utility methods to do TimeUnit Calculate
TimeUnit | getParentUnit(TimeUnit unit) get Parent Unit TimeUnit result = null; switch (unit) { case HOURS: result = TimeUnit.DAYS; break; case MINUTES: result = TimeUnit.HOURS; break; ... |
String | getProperUnitName(TimeUnit unit, long amount) Returns the appropriate spelling for a TimeUnit value based on the value of the "amount" parameter. String proper = unit.toString().substring(0, 1)
+ unit.toString().substring(1, unit.toString().length()).toLowerCase();
return amount != 1 ? proper : proper.substring(0, proper.length() - 1);
|
Date | getRandomTimeRound(int _duration, TimeUnit _unit) get random time in druation whit time unit from now. if (_duration < 0) { return new Date(); int i = new Random().nextInt(_duration); return new Date(new Date().getTime() + TimeUnit.MILLISECONDS.convert(i, _unit)); |
int | getTimeBucket(TimeUnit unit, long timestamp, int bucketSizeInSeconds) Floor long time to supplied Window int ts = timeToSeconds(unit, timestamp); return getWindowFlooredNaturalTime(ts, bucketSizeInSeconds); |
long | getTimeInMillis(TimeUnit unit) get Time In Millis switch (unit) { case MILLISECONDS: case SECONDS: case MINUTES: case HOURS: case DAYS: return unit.toMillis(1L); default: ... |
String | getTimeString(long value, TimeUnit unit) get Time String if (value <= 0) return ""; int i = unit.ordinal(); TimeUnit[] units = TimeUnit.values(); TimeUnit next = null; int factor = -1; if (i < factors.length - 1) { next = units[i + 1]; ... |
TimeUnit | getTimeUnit(Object units) get Time Unit if (units instanceof TimeUnit) { return (TimeUnit) units; } else if (units instanceof String) { return cleanUnitsString((String) units); throw new IllegalArgumentException("unable to parse returned time units: " + units.toString()); |
TimeUnit | getTimeUnit(String timeUnit, TimeUnit defaultUnit) get Time Unit TimeUnit timeUnit_ = TimeUnit.SECONDS; try { timeUnit_ = TimeUnit.valueOf(timeUnit); } catch (Exception e) { timeUnit_ = defaultUnit; return timeUnit_; |
TimeUnit | getTimeUnitByName(String timeUnit, TimeUnit defaultTimeUnit) get Time Unit By Name TimeUnit timeUnit_ = TimeUnit.SECONDS; if (timeUnit.equals("TimeUnit.SECONDS")) { timeUnit_ = TimeUnit.SECONDS; } else if (timeUnit.equals("TimeUnit.DAYS")) { try { timeUnit_ = TimeUnit.valueOf("DAYS"); } catch (Exception e) { timeUnit_ = defaultTimeUnit; ... |
String | getValueString(long value, TimeUnit unit) get Value String String result = value + " " + unit.toString().toLowerCase(); if (value == 1) { result = result.substring(0, result.length() - 1); return result; |