title |
---|
Duration Module | Juttle Language Reference |
Duration is the representation of a time interval in Juttle, defined as the time span between two Juttle moments; refer to the Time module for more. The Duration module provides functions for working with durations, including conversion from/to seconds and strings.
[TOC]
Return the value of duration as a floating-point number in units of timeunit.
Duration.as(duration, timeunit)
If you were to multiply this number by Duration(1, timeunit), you would get back the original duration.
Example: output elapsed time as seconds
{!docs/examples/modules/duration_as.juttle!}
Format the duration as a string.
Duration.format(duration)
Duration.format(duration, format_string)
The optional format_string
is as described in the npm moment-duration-format package. When no format is given, an approximate format will be built based on the magnitude of the duration.
Example
{!docs/examples/modules/duration_format.juttle!}
Return the value of a given time unit for a duration (such as, "days") as an integer.
Duration.get(duration, timeunit)
Example: split duration into its time unit components
{!docs/examples/modules/duration_get.juttle!}
Return the value of duration as a floating-point number in milliseconds.
Duration.milliseconds(duration)
ℹ️ Note:
Equivalent to Duration.as(duration, "ms")
.
Example: convert duration of Hadron Epoch to milliseconds
{!docs/examples/modules/duration_milliseconds.juttle!}
Return a duration.
Duration.new(seconds)
Example: Some ways to represent a minute
{!docs/examples/modules/duration_new.juttle!}
Return the value of duration as a floating-point number in units of seconds.
Duration.seconds(duration)
ℹ️ Note:
Equivalent to Duration.as(duration, "seconds")
.
Example: how many seconds in a year
{!docs/examples/modules/duration_seconds.juttle!}
Convert a value of type Duration to type String.
Duration.toString(duration)
Example: print duration of this day so far
{!docs/examples/modules/duration_to_string.juttle!}