mirror of
https://github.com/mailscope/kumomta.git
synced 2026-08-24 13:18:18 +00:00
6f31d5514c
Motivated by https://github.com/KumoCorp/kumomta/pull/403, this commit introduces reasonably full featured Time and TimeDelta types built atop the chrono crate. closes: https://github.com/KumoCorp/kumomta/pull/403
2.3 KiB
2.3 KiB
Time Object
{{since('dev')}}
The Time object represents a date and time. It internally stores the time as
UTC, even if it was produced by
parsing time from some other time zone.
Metamethods
The following metamethods are implemented on Time objects:
__tostring- returns a human readable representation of the time like1970-01-01 00:00:01 UTC.__eq- compares twoTimeobjects for equality+- addition. You may add a TimeDelta to aTimeto produce a newTimeoffset by the added delta.-- subtraction:
Fields
The following fields expose various properties of the underlying Time object.
Fields are accessed using dot notation, like time.rfc2822.
year- the year number portion of the ISO 8601 calendar date.month- the month number of the calendar date, starting with1for January.day- the day of the month of the calendar date, starting from1.hour- the hour number, from0to23.minute- the minute number, from0to59.second- the second number, from0to59.unix_timestamp- the number of non-leap seconds since January 1, 1970 0:00:00 UTC (aka "UNIX timestamp").unix_timestamp_millis- the number of non-leap milliseconds since January 1, 1970 0:00:00 UTC.rfc2822- the time formatted according to RFC 2822rfc3339- the time formatted according to RFC 3339elapsed- the TimeDelta corresponding to the difference between thisTimeobject and the time at which theelapsedfield is evaluated.
Methods
The following methods are implemented on Time objects. Methods are accessed
using colon notation, like time:format().
Time:format
local string = time:format '%H:%M:%S'
Formats the time object using the strftime syntax supported by the Rust chrono crate.
Parsing of the format string is lenient, but it is still possible that for invalid format strings to raise errors.