Interval
Library of functions for the interval type.
Functions
Build
Creates an interval.
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.
Interval.Build(hours = 1, minutes = 30)
Interval.Build(years = 3, months = 6, days = 5)
Days
"Gets the days part of an interval.
Interval.Days(value: interval)
Parameters
value
: The interval to get the days from.
Returns
int
: The number of days in the interval.
Interval.Days(Interval.Build(years = 2, days = 20))
// Result:
// 20
FromMillis
Converts a number of milliseconds to the corresponding interval
Interval.FromMillis(mills: long)
Parameters
mills
: The number of milliseconds to be converted to interval.
Returns
interval
: The interval representation of the value.
Interval.FromMillis(60000)
// Result:
// Interval(0,0,0,0,0,1,0,0)
Hours
"Gets the hours part of an interval.
Interval.Hours(value: interval)
Parameters
value
: The interval to get the hours from.
Returns
int
: The number of hours in the interval.
Interval.Hours(Interval.Build(years = 2, hours = 12))
// Result:
// 12
Millis
"Gets the milliseconds part of an interval.
Interval.Millis(value: interval)
Parameters
value
: The interval to get the milli-seconds from.
Returns
int
: The number of milliseconds in the interval.
Interval.Millis(Interval.Build(years = 2, millis = 230))
// Result:
// 230
Minutes
"Gets the minutes part of an interval.
Interval.Minutes(value: interval)
Parameters
value
: The interval to get the minutes from.
Returns
int
: The number of minutes in the interval.
Interval.Minutes(Interval.Build(years = 2, minutes = 15))
// Result:
// 15
Months
"Gets the months part of an interval.
Interval.Months(value: interval)
Parameters
value
: The interval to get the months from.
Returns
int
: The number of months in the interval.
Interval.Months(Interval.Build(years = 2, months = 10))
// Result:
// 10
Parse
"Parses an interval from a string.
Interval.Parse(str: string)
Parameters
str
: The string to be parsed as interval.
Returns
interval
: The interval representation of the string.
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)
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.
Interval.Seconds(value: interval)
Parameters
value
: The interval to get the seconds from.
Returns
int
: The number of seconds in the interval.
Interval.Seconds(Interval.Build(years = 2, seconds = 45))
// Result:
// 45
ToMillis
Converts a interval to the corresponding number of milliseconds
Interval.ToMillis(value: interval)
Parameters
value
: The interval to be converted to milliseconds.
Returns
long
: The number of milliseconds in the interval.
Interval.ToMillis(Interval.Build(minutes=1))
// Result:
// 60000
Interval.ToMillis(Interval.Build(days=1))
// Result:
// 86400000
Weeks
"Gets the weeks part of an interval.
Interval.Weeks(value: interval)
Parameters
value
: The interval to get the weeks from.
Returns
int
: The number of weeks in the interval.
Interval.Weeks(Interval.Build(years = 2, weeks = 4))
// Result:
// 4
Years
"Gets the years part of an interval.
Interval.Years(value: interval)
Parameters
value
: The interval to get the years from.
Returns
int
: The number of years in the interval.
Interval.Years(Interval.Build(years = 2, days = 20))
// Result:
// 2