Next: , Up: Time and Date   [Contents][Index]


5.31.1 Timestamps

As in UNIX, Librep measures time as the number of seconds since January 1st, 1970 (known as the epoch).

For historical reasons Librep stores “timestamp”s as a pair of integers, using a cons cell. The first integer records the number of whole days since the epoch, the second records the number of seconds since the start of the day (in universal time).

Function: current-time

Return the number of seconds since the epoch, in a cons-cell.

(current-time)
    ⇒ (10744 . 61063) 
Function: fix-time timestamp

Ensure that the two parts of timestamp (a pair or integers) are consistent, simply that the number of seconds is less than the number of seconds in a whole day. If not, the timestamp is adjusted to meet this constraint.

Function: time-later-p timestamp-1 timestamp-2

Returns true if timestamp-1 is later than timestamp-2.

On the plus side, this scheme won’t wrap around as quickly as UNIX’s time_t will ;-)

The rep.util.time module also provides some functions for manipulating timestamps:

Function: time->seconds timestamp

Convert timestamp to an integer, the number of seconds since the epoch that it represents.

Function: seconds->time seconds

Convert from an integer seconds to a timestamp object.

Function: time- timestamp-1 timestamp-2

Return the number of seconds difference between timestamp-1 and timestamp-2.

Constant: seconds-per-day

The number of seconds in a 24-hour day.