times

Namespace

times

Description:
  • Time and date/time related methods.
    Because method names are going to be used in templates, we keep them short, but descriptive.
    Method names are nouns describing what they return (rather than verbs), e.g. .time() and .minutes().

    All date/time related methods take their input as date/time strings (e.g. "2020-02-05T19:52:26") or Javascript date objects or Temporal objects. Some methods also accept time strings like "19:52:26".

    Methods ususally take one argument, and an additional options dictionary. See options for full documentation of available options.

    Some methods can be chained, for readability: secondsText(t1, t2).upper() is equivalent to upper(secondsText(t1, t2)).

Members

(static) now :string

Description:
  • Contains the current UTC time as a time string.
    This is a getter, meaning that the timestamp can change between two calls, during your template rendering session.
Contains the current UTC time as a time string.
This is a getter, meaning that the timestamp can change between two calls, during your template rendering session.
Type:
  • string
Example
// returns '2020-02-05T19:55:14.171Z'
now

Methods

(static) addHours(time, num) → {string}

Description:
  • Add (or subtract) a number of hours to a time.
    Note that the returned timestamp has no timezone data.
Example

sv

// returns '14'
addHours("13:40", 1).timeH()
Parameters:
Name Type Description
time Date | Temporal.Instant | string A datetime string or object
num number whole number of hours to add (positive) or subtract (negative)
Returns:
The new time
Type
string

(static) addMinutes(time, num) → {string}

Description:
  • Add (or subtract) a number of minutes to a time.
    Note that the returned timestamp has no timezone data.
Example

sv

// returns '13:50'
addMinutes("13:40", 10).timeHM()
Parameters:
Name Type Description
time Date | Temporal.Instant | string A datetime string or object
num number whole number of hours to add (positive) or subtract (negative)
Returns:
The new time
Type
string

(static) dayPeriod(time, optsopt) → {string}

Description:
  • Get a string representing the day period, such as "morning", "afternoon"
Example

sv

// returns 'eftermiddag'
dayPeriod("2020-02-05T13:10:00")

// returns 'på eftermiddagen'
dayPeriod("13:10:00", "format")
Parameters:
Name Type Attributes Description
time Date | string A date/time string or object
opts object <optional>
Options
Properties
Name Type Attributes Default Description
style string <optional>
'standAlone' 'standAlone' or 'format'
tzOffset string <optional>
Timezone offset in minutes
Returns:
day period
Type
string

(static) dayPeriodLong(time, optsopt) → {string}

Description:
  • Alias for dayPeriod(time, {style: "format"})
Example

sv

// returns 'på eftermiddagen'
dayPeriodLong("2020-02-05T13:10:00")
Parameters:
Name Type Attributes Description
time Date | string A date/time string or object
opts object <optional>
Options
Properties
Name Type Attributes Description
tzOffset string <optional>
Timezone offset in minutes
Returns:
day period
Type
string

(static) duration(time1, time2, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds
Example

sv

// returns '2 timmar och 1 minut'
duration("13:12:00", "15:13:00")

// returns '24 timmar och 1 minut'
duration("2018-12-11T13:12:00", "2018-12-12T15:13:00")

// returns '1 dygn och 1 minut'
duration("2018-12-11T13:12:00", "2018-12-12T15:13:00", {largestUnit: "days"})
Parameters:
Name Type Attributes Description
time1 Date | string A date/time string or object
time2 Date | string A date/time string or object
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
largestUnit string <optional>
{days|hours|minutes|seconds} Use to toggle between “26 hours” and “1 day, 2 hours”
smallestUnit string <optional>
{days|hours|minutes|seconds} Use to skip smaller units
Returns:
describing the time passed
Type
string

(static) durationFrom(duration, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds from a precalculated timespan
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns '2 minuter'
durationFrom({seconds: 120})

// returns '1 minut och 5 sekunder'
durationFrom({minutes: 2, seconds: 65})
Parameters:
Name Type Attributes Description
duration object A Temporal.Duration like set of units, but unlike native Temporal.Duration, this can have fractions
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromMinutes(minutes, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds from a number of seconds
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns '1 minut och 15 sekunder'
durationFromMinutes(1.25)
Parameters:
Name Type Attributes Description
minutes number An number of minutes
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromMinutesPretty(minutes, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds from a number of seconds
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns 'en minut och 15 sekunder'
durationFromMinutesPretty(1.25)
Parameters:
Name Type Attributes Description
minutes number An number of seconds
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromMinutesShort(minutes, optsopt) → {string}

Description:
  • Get an abbreviated duration in days, hours, minutes and seconds from a number of seconds
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns '1 min 15 sek'
durationFromMinutesShort(1.25)
Parameters:
Name Type Attributes Description
minutes number An number of minutes
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromMinutesText(minutes, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds from a number of seconds
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns 'en minut och femton sekunder'
durationFromMinutesText(1.25)
Parameters:
Name Type Attributes Description
minutes number An number of seconds
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromPretty(duration, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds from a precalculated timespan
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns '2 minuter'
durationFrom({seconds: 120})

// returns 'två minuter och 30 sekunder'
durationFromPretty({minutes: 2, seconds: 30})
Parameters:
Name Type Attributes Description
duration object A Temporal.Duration like set of units, but unlike native Temporal.Duration, this can have fractions
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromSeconds(seconds, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds from a number of seconds
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns '2 minuter och 5 sekunder'
durationFromSeconds(125)
Parameters:
Name Type Attributes Description
seconds number An integer number of seconds
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromSecondsPretty(seconds, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds from a number of seconds
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns 'två minuter och 35 sekunder'
durationFromSecondsText(155)
Parameters:
Name Type Attributes Description
seconds number An integer number of seconds
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromSecondsShort(seconds, optsopt) → {string}

Description:
  • Get an abbreviated duration in days, hours, minutes, and seconds from a number of seconds
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns '2 min 5 sek'
durationFromSecondsShort(125)
Parameters:
Name Type Attributes Description
seconds number An integer number of seconds
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromSecondsText(seconds, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds from a number of seconds
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns 'två minuter och fem sekunder'
durationFromSecondsText(125)
Parameters:
Name Type Attributes Description
seconds number An integer number of seconds
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromShort(duration, optsopt) → {string}

Description:
  • Get an abbreviated duration in days, hours, minutes and seconds from a precalculated timespan
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns '2 min'
durationFromShort({seconds: 120})

// returns '1 min och 5 sek'
durationFromShort({minutes: 2, seconds: 65})
Parameters:
Name Type Attributes Description
duration object A Temporal.Duration like set of units, but unlike native Temporal.Duration, this can have fractions
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationFromText(duration, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds from a precalculated timespan
    Note that unlike `duration()`, you will have to keep track of daylight saving, leap years etc yourself!
Example

sv

// returns '2 minuter'
durationFrom({seconds: 120})

// returns 'tre minuter och fem sekunder'
durationFromText({minutes: 2, seconds: 65})
Parameters:
Name Type Attributes Description
duration object A Temporal.Duration like set of units, but unlike native Temporal.Duration, this can have fractions
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationPretty(time1, time2, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds
Example

sv

// returns 'två timmar och 33 minuter'
durationPretty("13:12:00", "15:43:00")

// returns '24 timmar och en minut'
durationPretty("2018-12-11T13:12:00", "2018-12-12T15:13:00")

// returns 'ett dygn och en minut'
durationPretty("2018-12-11T13:12:00", "2018-12-12T15:13:00", {largestUnit: "days"})
Parameters:
Name Type Attributes Description
time1 Date | string A date/time string or object
time2 Date | string A date/time string or object
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) durationShort(time1, time2, optsopt) → {string}

Description:
  • Get a abbreviated duration in days, hours, minutes and seconds
Example

sv

// returns '2 tim 1 min'
durationShort("13:12:00", "15:13:00")

// returns '24 tim 1 min'
durationShort("2018-12-11T13:12:00", "2018-12-12T15:13:00")

// returns '1 d. 1 min'
durationShort("2018-12-11T13:12:00", "2018-12-12T15:13:00", {largestUnit: "days"})
Parameters:
Name Type Attributes Description
time1 Date | string A date/time string or object
time2 Date | string A date/time string or object
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
largestUnit string <optional>
{days|hours|minutes|seconds} Use to toggle between “26 hours” and “1 day, 2 hours”
smallestUnit string <optional>
{days|hours|minutes|seconds} Use to skip smaller units
Returns:
describing the time passed
Type
string

(static) durationText(time1, time2, optsopt) → {string}

Description:
  • Get a duration in days, hours, minutes and seconds
Example

sv

// returns 'två timmar och en minut'
durationText("13:12:00", "15:13:00")

// returns 'tjugofyra timmar och en minut'
durationText("2018-12-11T13:12:00", "2018-12-12T15:13:00")

// returns 'ett dygn och en minut'
durationText("2018-12-11T13:12:00", "2018-12-12T15:13:00", {largestUnit: "days"})
Parameters:
Name Type Attributes Description
time1 Date | string A date/time string or object
time2 Date | string A date/time string or object
opts object <optional>
Options
Returns:
describing the time passed
Type
string

(static) timeH(time, optsopt) → {string}

Description:
  • Get a string representing the current time, with hours and minutes
Examples

sv

// returns '13'
timeH("2020-02-05T13:10:00")

ja

// returns '13時'
timeH("2020-02-05T13:10:00")

es-ES

// returns '13'
timeH("2020-02-05T13:10:00")

es-US

// returns '1 p. m.'
timeH("2020-02-05T13:10:00")
Parameters:
Name Type Attributes Description
time Date | string A date/time string or object
opts object <optional>
Options
Properties
Name Type Attributes Description
tzOffset string <optional>
Timezone offset in minutes
Returns:
describing the number of months
Type
string

(static) timeHM(time, optsopt) → {string}

Description:
  • Get a string representing the current time, with hours and minutes
Example

sv

// returns '14.10'
timeHM("2020-02-05T14:10:00")
Parameters:
Name Type Attributes Description
time Date | string A date/time string or object
opts object <optional>
Options
Properties
Name Type Attributes Description
tzOffset string <optional>
Timezone offset in minutes
Returns:
describing the number of months
Type
string

(static) timeHMS(time, optsopt) → {string}

Description:
  • Get a string representing the current time, with hours, minutes and seconds
Example

sv

// returns '14.10:00'
timeHMS("2020-02-05T14:10:00")
Parameters:
Name Type Attributes Description
time Date | string A date/time string or object
opts object <optional>
Options
Properties
Name Type Attributes Description
tzOffset string <optional>
Timezone offset in minutes
Returns:
describing the number of months
Type
string