protected String getFormattedTime(String input) { if (input == null || input.equals("")) { return null; } long ts; switch (this.interpreter) { case SECONDS: ts = (long) (Double.parseDouble(input) * 1000); break; case MILLISECONDS: ts = (long) (Double.parseDouble(input)); break; default: throw new RuntimeException("Unknown interpreter"); } /* * Sanity check */ ts = Time.toMilliseconds(ts); /* * Round down */ if (this.secondsToRound > 0) { ts = Math.round((double) ts / (this.secondsToRound * 1000)) * (this.secondsToRound * 1000); } return this.dateTimeFormatter.print(ts); }
protected String getFormattedTime(String input) { if (input == null || input.equals("")) { return null; } long ts; switch (this.interpreter) { case SECONDS: ts = (long) (Double.parseDouble(input) * 1000); break; case MILLISECONDS: ts = (long) (Double.parseDouble(input)); break; default: throw new RuntimeException("Unknown interpreter"); } /* * Sanity check */ ts = Time.toMilliseconds(ts); /* * Round down */ if (this.secondsToRound > 0) { ts = Math.round((double) ts / (this.secondsToRound * 1000)) * (this.secondsToRound * 1000); } return this.dateTimeFormatter.print(ts); }
protected static long getTimestamp(String dvalue, TimeFieldType type) { long ts; switch (type) { case SECONDS: ts = (long) (Double.parseDouble(dvalue) * 1000); break; case MILLISECONDS: ts = (long) (Double.parseDouble(dvalue)); break; default: throw new OperationException("unsupported TimeFieldType"); } /* * Sanity Check */ try { return Time.toMilliseconds(ts); } catch (IllegalArgumentException e) { throw new OperationException(e); } }
protected static long getTimestamp(String dvalue, TimeFieldType type) { long ts; switch (type) { case SECONDS: ts = (long) (Double.parseDouble(dvalue) * 1000); break; case MILLISECONDS: ts = (long) (Double.parseDouble(dvalue)); break; default: throw new OperationException("unsupported TimeFieldType"); } /* * Sanity Check */ try { return Time.toMilliseconds(ts); } catch (IllegalArgumentException e) { throw new OperationException(e); } }
@Test public void testFromSeconds() { assertEquals(1484802359000L, Time.toMilliseconds(1484802359L)); }
@Test(expected = IllegalArgumentException.class) public void testInvalid() { assertEquals(1484802359000L, Time.toMilliseconds(1484802L)); } }
@Test public void testFromMicroseconds() { assertEquals(1484802359000L, Time.toMilliseconds(1484802359000000L)); }
@Test public void testFromNanoseconds() { assertEquals(1484802359000L, Time.toMilliseconds(1484802359000000000L)); }
@Test public void testFromMilliseconds() { assertEquals(1484802359000L, Time.toMilliseconds(1484802359000L)); }