pkg/time: add FormatDuration
issues: #1469
This change adds a new function to format a duration represented as an
integer in nanoseconds to a compact string representation. The string
representation is used in some applications configuration, I.e.
Prometheus.
It's possible to use CUE's string interpolation to provide a valid
configuration by dividing the nanoseconds by the smallest supported
duration multiplier and appending it's suffix. I.e.
"\(nanoseconds/time.Second)s"`.
But this has the downside that human readers of the resulting
configuration have to convert a duration to a more readable format
before being able to interpret the value inside as part of complete
configuration.
The implementation for this new function is the same as the String()
method of Go's time.Duration type of the standard library.
Signed-off-by: xinau <felix@ehrenpfort.de>
Change-Id: Ibfe455166ebc5f5b8f55f7360cefba1a05eac390
Signed-off-by: xinau <felix@ehrenpfort.de>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/531327
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
authored by