Functions
civilFromEmailString | I Converts a given RFC 5322 formatted (e.g |
civilFromString | I Converts a given RFC 3339 timestamp(e.g., |
civilToEmailString | I Converts a given Civil record to RFC 5322 format (e.g |
civilToString | I Obtain a RFC 3339 timestamp (e.g., |
dateValidate | I Check that days and months are within range as per Gregorian calendar rules. |
dayOfWeek | I Get the day of week for a specified date. |
getZone | I Return the time zone object of a given zone ID. |
loadSystemZone | I Load the default time zone of the system. |
monotonicNow | I Returns no of seconds from unspecified epoch. |
utcAddSeconds | I Returns UTC time that occurs seconds after |
utcDiffSeconds | I Returns difference in seconds between |
utcFromCivil | I Converts a given |
utcFromString | I Converts from RFC 3339 timestamp (e.g., |
utcNow | I Returns the UTC representing the current time (current instant of the system clock in seconds from the epoch of |
utcToCivil | I Converts a given |
utcToEmailString | I Converts a given UTC to an email formatted string (e.g |
utcToString | I Converts a given |
civilFromEmailString
Converts a given RFC 5322 formatted (e.g Wed, 10 Mar 2021 19:51:55 -0800 (PST)
) string to a civil record.
1time:Civil|time:Error emailDateTime = time:civilFromEmailString("Wed, 10 Mar 2021 19:51:55 -0820");
Parameters
- dateTimeString string
RFC 5322 formatted (e.g Wed, 10 Mar 2021 19:51:55 -0800 (PST)
) string to be converted
civilFromString
Converts a given RFC 3339 timestamp(e.g., 2007-12-03T10:15:30.00Z
) to time:Civil
.
1time:Civil|time:Error civil1 = time:civilFromString("2021-04-12T23:20:50.520+05:30[Asia/Colombo]");2time:Civil|time:Error civil2 = time:civilFromString("2007-12-03T10:15:30.00Z");
Parameters
- dateTimeString string
RFC 3339 timestamp (e.g., 2007-12-03T10:15:30.00Z
) as a string
civilToEmailString
function civilToEmailString(Civil civil, HeaderZoneHandling zoneHandling) returns string | Error
Converts a given Civil record to RFC 5322 format (e.g Wed, 10 Mar 2021 19:51:55 -0800 (PST)
).
1time:Civil civil = check time:civilFromString("2021-04-12T23:20:50.520+05:30[Asia/Colombo]");2string|time:Error emailDateTime = time:civilToEmailString(civil, time:PREFER_ZONE_OFFSET);
Parameters
- civil Civil
The civil record to be converted
- zoneHandling HeaderZoneHandling
Indicate how to handle the zone by specifying the preference whether to give preference to zone offset or time abbreviation. Also, this can configure to use zone offset to the execution and use time abbreviation as a comment.
civilToString
Obtain a RFC 3339 timestamp (e.g., 2007-12-03T10:15:30.00Z
) from a given time:Civil
.
1time:Civil civil = check time:civilFromString("2007-12-03T10:15:30.00Z");2string|time:Error civilString = time:civilToString(civil);
Parameters
- civil Civil
time:Civil
that needs to be converted
dateValidate
Check that days and months are within range as per Gregorian calendar rules.
1time:Date date = {year: 1994, month: 11, day: 7};2time:Error? isValid = time:dateValidate(date);
Parameters
- date Date
The date to be validated
dayOfWeek
Get the day of week for a specified date.
1time:Date date = {year: 1994, month: 11, day: 7};2time:DayOfWeek day = time:dayOfWeek(date);
Parameters
- date Date
Date value
getZone
Return the time zone object of a given zone ID.
Parameters
- id string
Time zone ID (e.g., "Continent/City")
loadSystemZone
Load the default time zone of the system.
monotonicNow
function monotonicNow() returns decimal
Returns no of seconds from unspecified epoch. This API guarantees consistent value increase in subsequent calls with nanoseconds precision.
1decimal seconds = time:monotonicNow();
utcAddSeconds
Returns UTC time that occurs seconds after utc
. This assumes that all days have 86400 seconds except when utc
represents a time during a positive leap second, in which case the corresponding day will be assumed to have 86401 seconds.
1time:Utc utc = time:utcAddSeconds(time:utcNow(), 20.900);
utcDiffSeconds
Returns difference in seconds between utc1
and utc2
.
This will be positive if utc1
occurs after utc2
1time:Utc utc1 = time:utcNow();2time:Utc utc2 = check time:utcFromString("2021-04-12T23:20:50.520Z");3time:Seconds seconds = time:utcDiffSeconds(utc1, utc2);
utcFromCivil
Converts a given Civil
value to an Utc
timestamp.
1time:Civil civil = time:utcToCivil(time:utcNow());2time:Utc utc = time:utcFromCivil(civil);
Parameters
- civilTime Civil
time:Civil
time
utcFromString
Converts from RFC 3339 timestamp (e.g., 2007-12-03T10:15:30.00Z
) to Utc.
1time:Utc|time:Error utc = time:utcFromString("2007-12-0310:15:30.00Z");
Parameters
- timestamp string
RFC 3339 timestamp (e.g., 2007-12-03T10:15:30.00Z
) value as a string
utcNow
Returns the UTC representing the current time (current instant of the system clock in seconds from the epoch of 1970-01-01T00:00:00
).
1time:Utc utc = time:utcNow();
Parameters
- precision int? (default ())
Specifies the number of zeros after the decimal point (e.g., 3 would give the millisecond precision and nil means native precision (nanosecond precision 9) of the clock)
utcToCivil
Converts a given time:Utc
timestamp to a time:Civil
value.
1time:Utc utc = time:utcNow();2time:Civil civil = time:utcToCivil(utc);
Parameters
- utc Utc
time:Utc
timestamp
utcToEmailString
function utcToEmailString(Utc utc, UtcZoneHandling zh) returns string
Converts a given UTC to an email formatted string (e.g Mon, 3 Dec 2007 10:15:30 GMT
).
1time:Utc utc = time:utcNow();2string emailFormattedString = time:utcToEmailString(utc);
Parameters
- utc Utc
The UTC value to be formatted
- zh UtcZoneHandling (default "0")
Type of the zone value to be added
utcToString
Converts a given time:Utc
time to a RFC 3339 timestamp (e.g., 2007-12-03T10:15:30.00Z
).
1string utcString = time:utcToString(time:utcNow());
Parameters
- utc Utc
Utc time as a tuple [int, decimal]