TimeRange implements Comparable<TimeRange> { public String format() { return TimeRangeFormatter.format(this); } TimeRange(@JsonProperty("duration") long duration,
                     @JsonProperty("timeUnit") TimeUnit timeUnit); long getDuration(); TimeUnit getTimeUnit(); TimeRange convert(TimeUnit timeUnit); long toMillis(); long toSeconds(); long get(TimeUnit targetTimeUnit); @Override int compareTo(TimeRange o); @Override boolean equals(Object o); @Override int hashCode(); String format(); @Override String toString(); static TimeRange ofMillis(long millis); static TimeRange ofSeconds(long seconds); static TimeRange ofMinutes(long minutes); static TimeRange ofHours(long hours); static TimeRange ofDays(long days); static TimeRange ofWeeks(long weeks); static TimeRange MAX_RANGE; }
@Test public void testFormat() throws Exception { assertEquals( "5m", new TimeRange( 300010, TimeUnit.MILLISECONDS ).format() ); assertEquals( "5m30s", new TimeRange( 330000, TimeUnit.MILLISECONDS ).format() ); assertEquals( "-5m30s", new TimeRange( -330000, TimeUnit.MILLISECONDS ).format() ); assertEquals( "100ms", new TimeRange( 100, TimeUnit.MILLISECONDS ).format() ); }