Skip to main content

Interval

Library of functions for the interval type.

Functions

Build

Creates an interval.

Syntax:
Interval.Build(years: optional int, months: optional int, weeks: optional int, days: optional int, hours: optional int, minutes: optional int, seconds: optional int, millis: optional int)
Parameters
  • years: Number of years in the interval.

  • months: Number of months in the interval.

  • weeks: Number of weeks in the interval.

  • days: Number of days in the interval.

  • hours: Number of hours in the interval.

  • minutes: Number of minutes in the interval.

  • seconds: Number of seconds in the interval.

  • millis: Number of milli-seconds in the interval.

Returns
  • interval: The interval representation of the value.
Example:
Interval.Build(hours = 1, minutes = 30)

Interval.Build(years = 3, months = 6, days = 5)

Days

"Gets the days part of an interval.

Syntax:
Interval.Days(value: interval)
Parameters
  • value: The interval to get the days from.
Returns
  • int: The number of days in the interval.
Example:
Interval.Days(Interval.Build(years = 2, days = 20))
// Result:
// 20

FromMillis

Converts a number of milliseconds to the corresponding interval

Syntax:
Interval.FromMillis(mills: long)
Parameters
  • mills: The number of milliseconds to be converted to interval.
Returns
  • interval: The interval representation of the value.
Example:
Interval.FromMillis(60000)
// Result:
// Interval(0,0,0,0,0,1,0,0)

Hours

"Gets the hours part of an interval.

Syntax:
Interval.Hours(value: interval)
Parameters
  • value: The interval to get the hours from.
Returns
  • int: The number of hours in the interval.
Example:
Interval.Hours(Interval.Build(years = 2, hours = 12))
// Result:
// 12

Millis

"Gets the milliseconds part of an interval.

Syntax:
Interval.Millis(value: interval)
Parameters
  • value: The interval to get the milli-seconds from.
Returns
  • int: The number of milliseconds in the interval.
Example:
Interval.Millis(Interval.Build(years = 2, millis = 230))
// Result:
// 230

Minutes

"Gets the minutes part of an interval.

Syntax:
Interval.Minutes(value: interval)
Parameters
  • value: The interval to get the minutes from.
Returns
  • int: The number of minutes in the interval.
Example:
Interval.Minutes(Interval.Build(years = 2, minutes = 15))
// Result:
// 15

Months

"Gets the months part of an interval.

Syntax:
Interval.Months(value: interval)
Parameters
  • value: The interval to get the months from.
Returns
  • int: The number of months in the interval.
Example:
Interval.Months(Interval.Build(years = 2, months = 10))
// Result:
// 10

Parse

"Parses an interval from a string.

Syntax:
Interval.Parse(str: string)
Parameters
  • str: The string to be parsed as interval.
Returns
  • interval: The interval representation of the string.
Example:
Interval.Parse("P1Y2M") // interval 1 year, 2 months
// Result:
// Interval(1,2,0,0,0,0,0,0)

Interval.Parse("PT1M2S") // interval 1 minute, 2 seconds
// Result:
// Interval(0,0,0,0,0,1,2,0)

Interval.Parse("P1Y2M3DT4H5M6.007S") // interval 1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds
// Result:
// Interval(1,2,0,3,4,5,6,7)
note

The interval format for the string has to be the ISO-8601 for durations, see https://en.wikipedia.org/wiki/ISO_8601#Durations.

Seconds

"Gets the seconds part of an interval.

Syntax:
Interval.Seconds(value: interval)
Parameters
  • value: The interval to get the seconds from.
Returns
  • int: The number of seconds in the interval.
Example:
Interval.Seconds(Interval.Build(years = 2, seconds = 45))
// Result:
// 45

ToMillis

Converts a interval to the corresponding number of milliseconds

Syntax:
Interval.ToMillis(value: interval)
Parameters
  • value: The interval to be converted to milliseconds.
Returns
  • long: The number of milliseconds in the interval.
Example:
Interval.ToMillis(Interval.Build(minutes=1))
// Result:
// 60000

Interval.ToMillis(Interval.Build(days=1))
// Result:
// 86400000

Weeks

"Gets the weeks part of an interval.

Syntax:
Interval.Weeks(value: interval)
Parameters
  • value: The interval to get the weeks from.
Returns
  • int: The number of weeks in the interval.
Example:
Interval.Weeks(Interval.Build(years = 2, weeks = 4))
// Result:
// 4

Years

"Gets the years part of an interval.

Syntax:
Interval.Years(value: interval)
Parameters
  • value: The interval to get the years from.
Returns
  • int: The number of years in the interval.
Example:
Interval.Years(Interval.Build(years = 2, days = 20))
// Result:
// 2