Microsecond support in java.time.Duration/Instant?
Roger Riggs
Roger.Riggs at Oracle.com
Mon Jan 22 14:25:00 UTC 2018
Hi Kurt,
In JSR 310, the thinking was that higher precision was desirable and
that adding
micros methods just bulked up the API without sufficient payback. At the
time there
were insufficient use cases to motivate the addition. If the use is
more common
than previously thought it is a straightforward addition.
Regards, Roger
On 1/21/2018 9:58 PM, Kurt Alfred Kluever wrote:
> Hi core-libs-dev,
>
> At Google, we often use microsecond precision for instants/durations
> (probably because of historical reasons). Therefore, we have a handful of
> static utility functions for creating/converting java.time types and
> microseconds:
>
> public static Duration ofMicros(long micros)
> public static long toMicros(Duration duration)
>
> public static Instant ofEpochMicros(long micros)
> public static long toEpochMicros(Instant instant)
>
> Duration includes APIs for creating/converting to days, hours, minutes,
> seconds, millis, and nanos. Instant includes APIs for creating/converting
> to seconds and millis. Micros are noticeably absent.
>
> I'm curious how these sets of units were chosen or decided upon? I
> understand that the line must be drawn somewhere (or else someone may come
> along asking for centisecond support), but I'm curious as to the rational.
>
> Thanks!
>
More information about the core-libs-dev
mailing list