Timestamp
Library of functions for the timestamp type.
Functions
AddInterval
Adds an interval to a timestamp.
Timestamp.AddInterval(timestamp: timestamp, interval: interval)
Parameters
timestamp
: Start timestamp.
interval
: interval to add.
let
t = Timestamp.Build(2018, 1, 1, 0, 0),
i = Interval.Build(years = 1, months = 2, days = 3, hours = 9, minutes = 30)
in
Timestamp.AddInterval(t, i) // 2019-03-04 09:30
Build
Builds a timestamp value
Timestamp.Build(year: int, month: int, day: int, hours: int, minutes: int, seconds: optional int, millis: optional int)
Parameters
year
: Year component of the timestamp to build.
month
: Month component of the timestamp to build.
day
: Day component of the timestamp to build.
hours
: Hours component of the timestamp to build.
minutes
: Minutes component of the timestamp to build.
seconds
: Seconds component of the timestamp to build.
millis
: Milliseconds component of the timestamp to build.
Timestamp.Build(2022, 1, 15, 9, 30) // 2022-01-15 09:30:00
Timestamp.Build(2022, 1, 15, 9, 30, seconds = 20) // 2022-01-15 9:30:20
Timestamp.Build(2022, 1, 15, 9, 30, seconds = 20, millis = 10) //2022-01-15 9:30:20.010
Day
Returns the day component of the timestamp.
Timestamp.Day(timestamp: timestamp)
Parameters
timestamp
: The timestamp from which the day component is extracted.
Timestamp.Day(Timestamp.Build(1975, 6, 23, 9, 30)) // 23
FromDate
Builds a timestamp from a date.
Timestamp.FromDate(date: date)
Parameters
date
: The date to convert to timestamp.
Timestamp.FromDate(Date.Build(1975, 6, 23)) // 1975-06-23 00:00:00
FromUnixTimestamp
Builds a timestamp from a Unix epoch (number of seconds since 01-01-1970).
Timestamp.FromUnixTimestamp(epoch: long)
Parameters
epoch
: Unix epoch (number of seconds since 01-01-1970).
Timestamp.FromUnixTimestamp(1517443320) // 2018-02-1 01:02:00
Hour
Returns the hours component of the timestamp.
Timestamp.Hour(timestamp: timestamp)
Parameters
timestamp
: The timestamp from which the hours component is extracted.
Timestamp.Hour(Timestamp.Build(1975, 6, 23, 9, 30)) // 9
Millis
Returns the milliseconds component of the timestamp.
Timestamp.Millis(timestamp: timestamp)
Parameters
timestamp
: The timestamp from which the year milliseconds is extracted.
Timestamp.Millis(Timestamp.Build(1975, 6, 23, 9, 30, seconds = 15, millis = 123)) // 123
Minute
Returns minutes part of the timestamp as an integer.
Timestamp.Minute(timestamp: timestamp)
Parameters
timestamp
: The timestamp from which the minutes component is extracted.
Timestamp.Minute(Timestamp.Build(1975, 6, 23, 9, 30)) // 30
Month
Returns the month component of the timestamp.
Timestamp.Month(timestamp: timestamp)
Parameters
timestamp
: The timestamp from which the month component is extracted.
Timestamp.Month(Timestamp.Build(1975, 6, 23, 9, 30)) // 6
Now
Returns the current timestamp.
Timestamp.Now()
Parse
Parses a timestamp from a string.
Timestamp.Parse(value: string, format: string)
Parameters
value
: The string to convert to timestamp.
format
: The format of the timestamp.
Timestamp.Parse("23/06/1975 09:30:15.123", "d/M/yyyy H:m:s.SSS") // 1975-06-23T09:30:15.123
Timestamp.Parse("9:30 23 June 1975", "H:m d MMMM yyyy") // 1975-06-23T09:30:00
Details
For more information about format strings see the Temporal templates documentation.
Range
Builds a collection of timestamps between two specified timestamps.
Timestamp.Range(start: timestamp, end: timestamp, step: optional interval)
Parameters
start
: The starting value.
end
: The end value (not included).
step
: The step value (default: Interval.Build(days=1)).
Timestamp.Range(Timestamp.Build(1975, 6, 23, 9, 30), Timestamp.Build(1975, 6, 28, 9, 30), step=Interval.Build(days=2))
Second
Returns the seconds component of the timestamp.
Timestamp.Second(timestamp: timestamp)
Parameters
timestamp
: The timestamp from which the seconds component is extracted.
Timestamp.Second(Timestamp.Build(1975, 6, 23, 9, 30, seconds = 15)) // 15
Subtract
Subtracts two timestamps.
Timestamp.Subtract(timestamp1: timestamp, timestamp2: timestamp)
Parameters
timestamp1
: Timestamp to be subtracted (minuend).
timestamp2
: Timestamp to subtract (subtrahend).
let
t1 = Timestamp.Build(2019, 3, 4, 9, 30),
t2 = Timestamp.Build(2018, 1, 1, 0, 0)
in
Timestamp.Subtract(t1, t2) // interval: years=1, months=2, days=3, hours=9, minutes=30
SubtractInterval
Subtracts an interval to a timestamp.
Timestamp.SubtractInterval(timestamp: timestamp, interval: interval)
Parameters
timestamp
: Start timestamp.
interval
: Interval to subtract.
let
t = Timestamp.Build(2019, 3, 4, 9, 30),
i = Interval.Build(years = 1, months = 2, days = 3, hours = 9, minutes = 30)
in
Timestamp.Subtract(t, i) // 2018-01-01 00:00
TimeBucket
Truncates a timestamp to the specified precision.
Valid string values for precision are:
- milliseconds
- second
- minute
- hour
- day
- week
- month
- quarter
- year
- decade
- century
- millennium
Timestamp.TimeBucket(value: interval or string, timestamp.: timestamp)
Parameters
value
: Interval or string definition to which the timestamp will be truncated.
timestamp.
: The timestamp to truncate.
Timestamp.TimeBucket(Interval.Build(millis = 100), Timestamp.Build(2007, 3, 14, 1, 2, seconds = 3, millis =4 )) // "2007-03-14 01:02:03.000"
Timestamp.TimeBucket(Interval.Build(years = 2), Timestamp.Build(2007, 3, 14, 1, 2, seconds = 3, millis =4 )) // "2006-01-01 00:00:00"
Timestamp.TimeBucket("hour", Timestamp.Build(2007, 3, 14, 1, 2, seconds = 3, millis =4 )) // "2007-03-14 01:00:00"
Timestamp.TimeBucket("year", Timestamp.Build(2007, 3, 14, 1, 2, seconds = 3, millis =4 )) // "2007-01-01 00:00:00"
ToUnixTimestamp
Converts a timestamp into the corresponding Unix epoch (number of seconds since 01-01-1970).
Timestamp.ToUnixTimestamp(timestamp: timestamp)
Parameters
timestamp
: Timestamp to convert to Unix epoch.
Timestamp.ToUnixTimestamp(Timestamp.Build(2018, 2, 1, 1, 2)) // 1517443320
Year
Returns the year component of the timestamp.
Timestamp.Year(timestamp: timestamp)
Parameters
timestamp
: The timestamp from which the year component is extracted.
Timestamp.Year(Timestamp.Build(1975, 6, 23, 9, 30)) // 1975