Skip to content

Latest commit

 

History

History
134 lines (83 loc) · 2.44 KB

duration.md

File metadata and controls

134 lines (83 loc) · 2.44 KB
title
Duration Module | Juttle Language Reference

Duration

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]


Duration.as

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!}

Duration.format

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!}

Duration.get

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!}

Duration.milliseconds

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!}

Duration.new

Return a duration.

Duration.new(seconds)

Example: Some ways to represent a minute

{!docs/examples/modules/duration_new.juttle!}

Duration.seconds

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!}

Duration.toString()

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!}