Type timeval is exactly the same as type datetime. The only difference is the default return. The return value of a timeval type is the value as a UNIX time stamp, while type datetime returns with the time as a string in ISO8601 format.

Why type timeval? It is possible to return a datetime as int(datetime) to get the UNIX time stamp, so why use timeval? It is often easier to work with time stamps then with time as string values.


tv = timeval(2020, 12, 10);   /* type timeval, 10 December 2020 */
dt = datetime(2020, 12, 10);  /* type datetime, 10 December 2020 */
assert (tv == dt);            /* true, both have the same time */
assert (type(tv) == 'timeval');
assert (type(dt) == 'datetime');
    dt: dt,
    tv: tv
};  // Return value is different

Return value in JSON format

    "dt": "2020-12-10T00:00:00Z",
    "tv": 1607558400


Function Description
extract Return a thing with second, minute, hour, day, month, year and gmt_offset as individual properties.
format Returns a string representation using a custom format string.
move Return a new timeval which is shifted in time relative to the original date/time.
replace Return a new timeval with new values for given time units.
to Return a new timeval with new time zone information.
week Return the week of the year as an integer between 0..53. Week 1 starts at the first Sunday in January.
weekday Return the number of days (0..6) since the last Sunday.
yday Return the day in the year as an integer value between 0..365 where the first of January is day 0.
zone Return the time zone as a string, of nil if not zone information is available.

The above functions correspond to those of a datetime object. For that reason, they are only listed under the data type datetime.

Function Description
timeval Create a new timeval value.
is_timeval Test if a given value is of type timeval.