XSB is a capable Prolog/Datalog implementation which allows for easy integration with C functions. This package defines a set of functions for using some of the C date-time functions in XSB.
To use the timestamp
module, put the timestamp.c
and timestamp.H
files into the current working directory or into one of the directories defined by library_directory(Dir)
(see section 3.6 of the XSM Manual 1).
As a simple example, we have the following test_timestamp.P file:
:- import localdatetime/1, to_timestamp/3, from_date/2, timestamps_age/3, from_timestamp/3, to_date/2, to_days/2 from timestamp. test :- TS is 0, to_date(TS, Date), writeln('OriginDate'=Date), fail. test :- to_timestamp('1970-01-01','%Y-%m-%d', TS), localdatetime(Now), timestamps_age(Now, TS, Age), writeln('AgeFromOrigin'=Age), fail. test :- localdatetime(Now), from_timestamp(Now, '%Y-%m-%d %H:%M:%S', DateTime), writeln('DateTimeNow'=DateTime), fail. test:- localdatetime(Now), to_date(Now, Date), writeln('DateNow'=Date), fail. test :- localdatetime(Now), to_days(Now, Days), writeln('DaysFromOrigin'=Days), fail. ?- test; true.
We can run this using:
xsb timestamp
xsb test_timestamp
OriginDate = 1970-01-01 AgeFromOrigin = 51 DateTimeNow = 2021-07-21 11:57:09 DateNow = 2021-07-21 DaysFromOrigin = 18829
Alternatively, we could run this within an XSB session using:
[timestamp]. [test_timestamp].
Documentation is available in the timestamp.c file.