@Test public void testConversion() { Assert.assertEquals(new Integer(23), GoTimeUtil.durationSeconds("23s")); Assert.assertEquals(new Integer(0), GoTimeUtil.durationSeconds("0.5s")); Assert.assertEquals(new Integer(0), GoTimeUtil.durationSeconds("3ms")); Assert.assertEquals(new Integer(0), GoTimeUtil.durationSeconds("3ns")); Assert.assertEquals(new Integer(1), GoTimeUtil.durationSeconds("1002ms")); Assert.assertEquals(new Integer(123), GoTimeUtil.durationSeconds("2m3s")); Assert.assertEquals(new Integer(3663), GoTimeUtil.durationSeconds("1h1m3s")); Assert.assertEquals(new Integer(1810), GoTimeUtil.durationSeconds("0.5h0.1m4s")); Assert.assertEquals(new Integer(-15), GoTimeUtil.durationSeconds("-15s")); Assert.assertEquals(new Integer(30), GoTimeUtil.durationSeconds("2h-119.5m")); }
public static Integer durationSeconds(String duration) { BigDecimal ns = durationNs(duration); if (ns == null) { return null; } BigDecimal sec = ns.divide(new BigDecimal(1_000_000_000)); if (sec.compareTo(new BigDecimal(Integer.MAX_VALUE)) > 0) { throw new IllegalArgumentException("Integer Overflow"); } return sec.intValue(); }
GoTimeUtil { public static Integer durationSeconds(String duration) { BigDecimal ns = durationNs(duration); if (ns == null) { return null; } BigDecimal sec = ns.divide(new BigDecimal(1_000_000_000)); if (sec.compareTo(new BigDecimal(Integer.MAX_VALUE)) > 0) { throw new IllegalArgumentException("Integer Overflow"); } return sec.intValue(); } }
GoTimeUtil { public static Integer durationSeconds(String duration) { BigDecimal ns = durationNs(duration); if (ns == null) { return null; } BigDecimal sec = ns.divide(new BigDecimal(1_000_000_000)); if (sec.compareTo(new BigDecimal(Integer.MAX_VALUE)) > 0) { throw new IllegalArgumentException("Integer Overflow"); } return sec.intValue(); } private  GoTimeUtil(); }
GoTimeUtil { public static Integer durationSeconds(String duration) { BigDecimal ns = durationNs(duration); if (ns == null) { return null; } BigDecimal sec = ns.divide(new BigDecimal(1_000_000_000)); if (sec.compareTo(new BigDecimal(Integer.MAX_VALUE)) > 0) { throw new IllegalArgumentException("Integer Overflow"); } return sec.intValue(); } private  GoTimeUtil(); static Integer durationSeconds(String duration); static BigDecimal durationNs(String durationP); }
GoTimeUtil { public static Integer durationSeconds(String duration) { BigDecimal ns = durationNs(duration); if (ns == null) { return null; } BigDecimal sec = ns.divide(new BigDecimal(1_000_000_000)); if (sec.compareTo(new BigDecimal(Integer.MAX_VALUE)) > 0) { throw new IllegalArgumentException("Integer Overflow"); } return sec.intValue(); } private  GoTimeUtil(); static Integer durationSeconds(String duration); static BigDecimal durationNs(String durationP);  }