List of utility methods to do TimeUnit Calculate
int | getWindowFlooredBinaryTime(TimeUnit unit, long timestamp, int windowSizeInSeconds) get Window Floored Binary Time timestamp = timeToNanoSeconds(unit, timestamp); System.err.println("shift:" + (MAX_BITS_TO_SHIFT - Integer.numberOfLeadingZeros(windowSizeInSeconds))); int ts = (int) (timestamp >> (MAX_BITS_TO_SHIFT - Integer.numberOfLeadingZeros(windowSizeInSeconds))); return ts; |
String | humanReadableTime(long time, TimeUnit unit) Convert the given time to a human readable string representation. final TimeUnit unit1 = largestNonzeroUnit(time, unit); final long value1 = time / unit.convert(1, unit1); final long timeRemainder = time % unit.convert(1, unit1); if (unit1 == NANOSECONDS || timeRemainder == 0) { return String.format("%d %s", value1, unit1.name().toLowerCase()); } else { final TimeUnit unit2 = largestNonzeroUnit(timeRemainder, unit); final long value2 = timeRemainder / unit.convert(1, unit2); ... |
boolean | isValidTimeUnit(String timeUnit) is Valid Time Unit for (TimeUnit type : TimeUnit.values()) { if (type.name().equalsIgnoreCase(timeUnit)) { return true; return false; |
void | logTiming(String description, int n, long time, TimeUnit unit) log Timing System.out.format("%s = %,d %s (n = %,d)%n", description, time, unit.name().toLowerCase(), n);
|
void | mapByName(TimeUnit... units) map By Name for (TimeUnit unit : units) {
UNIT_MAPPING.put(unit.name().toLowerCase(), unit);
|
Date | minus(Date date, int interval, TimeUnit unit) minus switch (unit) { case DAYS: return minusDays(date, interval); case HOURS: return minusHours(date, interval); case MINUTES: return minusMinutes(date, interval); case SECONDS: ... |
Optional | parseTimeUnit(final String unit) parse Time Unit return Optional.ofNullable(unit).map(String::toUpperCase).map(TimeUnit::valueOf);
|
TimeUnit | parseTimeUnit(Object property, TimeUnit defaultValue) parse Time Unit try { if (property instanceof String) return TimeUnit.valueOf((String) property); if (property instanceof TimeUnit) return (TimeUnit) property; if (property != null) return TimeUnit.valueOf(property.toString()); } catch (Exception ignore) { ... |
void | pause(long duration, TimeUnit unit) pause try { Thread.sleep(unit.toMillis(duration)); } catch (InterruptedException e) { |
String | printTime(long time, TimeUnit unit) print Time long ns = TimeUnit.NANOSECONDS.convert(time, unit); long us = TimeUnit.MICROSECONDS.convert(time, unit); long ms = TimeUnit.MILLISECONDS.convert(time, unit); long secs = TimeUnit.SECONDS.convert(time, unit); if (secs > 0) return secs + "s"; if (ms > 0) return ms + "ms"; ... |