Skip to main content

Time

Library of functions for the time type.

Functions

AddInterval

Adds an interval to a time.

Syntax:
Time.AddInterval(time: time, interval: interval)
Parameters
  • time: Start time.

  • interval: interval to add.

Returns
  • time: The time resulting from adding the interval to the start time.
Example:
let
t = Time.Build(0, 0),
i = Interval.Build(hours = 9, minutes = 30)
in
Time.AddInterval(t, i)
// Result:
// 09:30
caution

Note that years, months, weeks and days of interval will be ignored.

Build

Builds a time value.

Syntax:
Time.Build(hours: int, minutes: int, seconds: optional int, milliseconds: optional int)
Parameters
  • hours: Hours component of the time to build.

  • minutes: Minutes component of the time to build.

  • seconds: Seconds component of the time to build.

  • milliseconds: Milliseconds component of the time to build.

Returns
  • time: The time built from the given components.
Example:
Time.Build(9, 30)
// Result:
// 9:30:00.000

Time.Build(9, 30, seconds = 20)
// Result:
// 9:30:20.000

Time.Build(9, 30, seconds = 20, millis = 10)
// Result:
// 9:30:20.010

Hour

Returns the hours component of a time.

Syntax:
Time.Hour(time: time)
Parameters
  • time: The time from which the hours component is extracted.
Returns
  • int: The hours component of the given time.
Example:
Time.Hour(Time.Build(9, 30))
// Result:
// 9

Millis

Returns the milliseconds component of a time.

Syntax:
Time.Millis(time: time)
Parameters
  • time: The time from which the milliseconds component is extracted.
Returns
  • int: The milliseconds component of the given time.
Example:
Time.Millis(Time.Build(9, 30, millis=123))
// Result:
// 123

Minute

Returns the minutes component of a time.

Syntax:
Time.Minute(time: time)
Parameters
  • time: The time from which the minutes component is extracted.
Returns
  • int: The minutes component of the given time.
Example:
Time.Minute(Time.Build(9, 30))
// Result:
// 30

Now

Returns the current time.

Syntax:
Time.Now()
Returns
  • time: The current time.
Example:
Time.Now()

Parse

Parses a time from a string.

Syntax:
Time.Parse(value: string, format: string)
Parameters
  • value: The string to convert to time.

  • format: The format of the time.

Returns
  • time: The time parsed from the given string.
Example:
Time.Parse("09:12:23.450", "H:m:s.SSS")
// Result:
// 9:12:23.450""

Time.Parse("09:12 PM", "h:m a")
// Result:
// 21:12:00.000""

Details

For more information about format strings see the Temporal templates documentation.

Second

Returns the seconds component of a time.

Syntax:
Time.Second(time: time)
Parameters
  • time: The time from which the seconds component is extracted.
Returns
  • int: The seconds component of the given time.
Example:
Time.Seconds(Time.Build(9, 30, seconds=15))
// Result:
// 15

Subtract

Subtracts two times.

Syntax:
Time.Subtract(time1: time, time2: time)
Parameters
  • time1: Time to be subtracted (minuend).

  • time2: Time to subtract (subtrahend).

Returns
  • interval: The interval between the two times.
Example:
let
t1 = Time.Build(9, 30),
t2 = Time.Build(0, 0)
in
Time.Subtract(t1, t2)
// Result:
// interval: hours=9, minutes=30"

SubtractInterval

Subtracts an interval to a time.

Syntax:
Time.SubtractInterval(time: time, interval: interval)
Parameters
  • time: Start time.

  • interval: Interval to subtract.

Returns
  • time: The time resulting from subtracting the interval to the start time.
Example:
let
t = Time.Build(9, 30),
i = Interval.Build(hours = 9, minutes = 30)
in
Time.SubtractInterval(t, i)
// Result:
// 00:00
caution

Note that years, months, weeks and days of interval will be ignored.