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.
Returns
timestamp
: The timestamp with the interval added.
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)
// Result:
// 2019-03-04 09:30:00
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)
// Result:
// 2022-01-15 09:30:00
Timestamp.Build(2022, 1, 15, 9, 30, seconds = 20)
// Result:
// 2022-01-15 9:30:20
Timestamp.Build(2022, 1, 15, 9, 30, seconds = 20, millis = 10)
// Result:
// 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.
Returns
int
: The day component of the timestamp.
Timestamp.Day(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 23
FromDate
Builds a timestamp from a date.
Timestamp.FromDate(date: date)
Parameters
date
: The date to convert to timestamp.
Returns
timestamp
: The timestamp value.
Timestamp.FromDate(Date.Build(1975, 6, 23))
// Result:
// 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).
Returns
timestamp
: The timestamp corresponding to the Unix epoch.
Timestamp.FromUnixTimestamp(1517443320)
// Result:
// 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.
Returns
int
: The hours component of the timestamp.
Timestamp.Hour(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 9
Millis
Returns the milliseconds component of the timestamp.
Timestamp.Millis(timestamp: timestamp)
Parameters
timestamp
: The timestamp from which the year milliseconds is extracted.
Returns
int
: The milliseconds component of the timestamp.
Timestamp.Millis(Timestamp.Build(1975, 6, 23, 9, 30, seconds = 15, millis = 123)) // 123
// Result:
// 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.
Returns
int
: The minutes component of the timestamp.
Timestamp.Minute(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 30
Month
Returns the month component of the timestamp.
Timestamp.Month(timestamp: timestamp)
Parameters
timestamp
: The timestamp from which the month component is extracted.
Returns
int
: The month component of the timestamp.
Timestamp.Month(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 6
Now
Returns the current timestamp.
Timestamp.Now()
Returns
timestamp
: 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.
Returns
timestamp
: The timestamp value.
Timestamp.Parse("23/06/1975 09:30:15.123", "d/M/yyyy H:m:s.SSS")
// Result:
// 1975-06-23 09:30:15.123
Timestamp.Parse("9:30 23 June 1975", "H:m d MMMM yyyy")
// Result:
// 1975-06-23 09: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)).