Previous: , Up: The Standard Library   [Contents][Index]


11.8 Dates and Times

Often a format encodes a date and time expressed as the number of seconds since midnight, January 1st 1970. You could map these simply as integers. However, the standard library provides two types POSIX_Time32 and POSIX_Time64 which include pretty-printers (see Pretty Printers) to display the date in a human readable format. The definition is:

deftype POSIX_Timesize = struct
{
  uint<size>  seconds;

  defun _print = void:
  { … }
}

where size is either 32 or 64. When pretty printing is enabled, a mapped value of these types will display similar to

#<2019-Dec-12 8:54:56>

whereas when pretty printing is not enabled, this example would be displayed as:

POSIX_Time32 {seconds=1576140896U}

Note that timestamps of this type do not account for leap seconds and are agnostic towards timezone.

Occasionally you might wish to print an unmapped timestamp value in a human readable format. To do this, you can use the ptime function, which is defined as follows:

defun ptime = (uint<64> seconds) void:
{ … }