@Test public void testTimeToSeconds() { long time = System.currentTimeMillis() / 1000 / 3600; int timeToSeconds = TimeUtils.timeToSeconds(TimeUnit.HOURS, time); assertEquals(time * 3600, timeToSeconds); time = System.currentTimeMillis() * 1000 * 1000; timeToSeconds = TimeUtils.timeToSeconds(TimeUnit.NANOSECONDS, time); assertEquals(time / 1000 / 1000 / 1000, timeToSeconds); }
public static int timeToSeconds(TimeUnit unit, long time) { int ts; switch (unit) { case NANOSECONDS: ts = (int) (time / (1000 * 1000 * 1000)); break; case MICROSECONDS: ts = (int) (time / (1000 * 1000)); break; case MILLISECONDS: ts = (int) (time / 1000); break; case SECONDS: ts = (int) time; break; case MINUTES: ts = (int) (time * 60); break; case HOURS: ts = (int) (time * 3600); break; case DAYS: ts = (int) (time * 3600 * 24); break; default: throw ARGUMENT_EXCEPTION; } return ts; }
TimeUtils { public static int timeToSeconds(TimeUnit unit, long time) { int ts; switch (unit) { case NANOSECONDS: ts = (int) (time / (1000 * 1000 * 1000)); break; case MICROSECONDS: ts = (int) (time / (1000 * 1000)); break; case MILLISECONDS: ts = (int) (time / 1000); break; case SECONDS: ts = (int) time; break; case MINUTES: ts = (int) (time * 60); break; case HOURS: ts = (int) (time * 3600); break; case DAYS: ts = (int) (time * 3600 * 24); break; default: throw ARGUMENT_EXCEPTION; } return ts; } }
TimeUtils { public static int timeToSeconds(TimeUnit unit, long time) { int ts; switch (unit) { case NANOSECONDS: ts = (int) (time / (1000 * 1000 * 1000)); break; case MICROSECONDS: ts = (int) (time / (1000 * 1000)); break; case MILLISECONDS: ts = (int) (time / 1000); break; case SECONDS: ts = (int) time; break; case MINUTES: ts = (int) (time * 60); break; case HOURS: ts = (int) (time * 3600); break; case DAYS: ts = (int) (time * 3600 * 24); break; default: throw ARGUMENT_EXCEPTION; } return ts; } private  TimeUtils(); }
TimeUtils { public static int timeToSeconds(TimeUnit unit, long time) { int ts; switch (unit) { case NANOSECONDS: ts = (int) (time / (1000 * 1000 * 1000)); break; case MICROSECONDS: ts = (int) (time / (1000 * 1000)); break; case MILLISECONDS: ts = (int) (time / 1000); break; case SECONDS: ts = (int) time; break; case MINUTES: ts = (int) (time * 60); break; case HOURS: ts = (int) (time * 3600); break; case DAYS: ts = (int) (time * 3600 * 24); break; default: throw ARGUMENT_EXCEPTION; } return ts; } private  TimeUtils(); static int getTimeBucket(TimeUnit unit, long timestamp, int bucketSizeInSeconds); static int getWindowFlooredBinaryTime(TimeUnit unit, long timestamp, int windowSizeInSeconds); static int timeToSeconds(TimeUnit unit, long time); static int timeToMilliSeconds(TimeUnit unit, long time); static long timeToNanoSeconds(TimeUnit unit, long time); static int getWindowFlooredNaturalTime(int timeInSeconds, int bucketInSeconds); static long getTimeFromBucketString(String hexTimeInSeconds); static long getTimeFromBucketString(int timeInSeconds); }
TimeUtils { public static int timeToSeconds(TimeUnit unit, long time) { int ts; switch (unit) { case NANOSECONDS: ts = (int) (time / (1000 * 1000 * 1000)); break; case MICROSECONDS: ts = (int) (time / (1000 * 1000)); break; case MILLISECONDS: ts = (int) (time / 1000); break; case SECONDS: ts = (int) time; break; case MINUTES: ts = (int) (time * 60); break; case HOURS: ts = (int) (time * 3600); break; case DAYS: ts = (int) (time * 3600 * 24); break; default: throw ARGUMENT_EXCEPTION; } return ts; } private  TimeUtils(); static int getTimeBucket(TimeUnit unit, long timestamp, int bucketSizeInSeconds); static int getWindowFlooredBinaryTime(TimeUnit unit, long timestamp, int windowSizeInSeconds); static int timeToSeconds(TimeUnit unit, long time); static int timeToMilliSeconds(TimeUnit unit, long time); static long timeToNanoSeconds(TimeUnit unit, long time); static int getWindowFlooredNaturalTime(int timeInSeconds, int bucketInSeconds); static long getTimeFromBucketString(String hexTimeInSeconds); static long getTimeFromBucketString(int timeInSeconds);  }