NOTE: Development of these functions has been moved to souffle-lib.
Souffle is a capable Datalog implementation which allows for easy integration with C functions. This package defines a set of functors for using some of the C date-time functions in Souffle.
As a simple example, we have the following Souffle test.dl file:
#include "datetime.dl" .decl Times(timestamp:timestamp) .decl Test(operator:symbol, timestamp:timestamp, result:symbol) Times(@from_date("1970-01-01")) :- true. Times(@from_date_time("1970-01-02 00:00:00")) :- true. Times(@to_timestamp("03/01/1970", "%d/%m/%Y")) :- true. Times(@now()) :- true. Times(@from_date("")) :- true. Test("@to_day", timestamp, to_string(@to_day(timestamp))) :- Times(timestamp). Test("@to_date", timestamp, @to_date(timestamp)) :- Times(timestamp). Test("@to_date_time", timestamp, @to_date_time(timestamp)) :- Times(timestamp). Test("@from_timestamp", timestamp, @from_timestamp(timestamp,"%d/%m/%Y")) :- Times(timestamp). Test("@age", timestamp1, to_string(@age(timestamp1,timestamp2))) :- Times(timestamp1), Times(timestamp2), timestamp1<timestamp2. .output Test
This reads in the functor definitions, declares relationships for times and test results, and calculates test results for each of the times. The code to run this in the interpreter is souffle test.dl
or, in the compiler, souffle -c test.dl
. As an example:
g++ -shared -fPIC datetime.cpp -o libfunctors.so
souffle test.dl
cat Test.csv
@to_day | -2209078814 | -25568 |
@to_day | -3600 | 0 |
@to_day | 82800 | 1 |
@to_day | 169200 | 2 |
@to_day | 1621026306 | 18761 |
@to_date | -2209078814 | 1899-12-31 |
@to_date | -3600 | 1970-01-01 |
@to_date | 82800 | 1970-01-02 |
@to_date | 169200 | 1970-01-03 |
@to_date | 1621026306 | 2021-05-14 |
@to_date_time | -2209078814 | 1899-12-31 00:00:00 |
@to_date_time | -3600 | 1970-01-01 00:00:00 |
@to_date_time | 82800 | 1970-01-02 00:00:00 |
@to_date_time | 169200 | 1970-01-03 00:00:00 |
@to_date_time | 1621026306 | 2021-05-14 23:05:06 |
@from_timestamp | -2209078814 | 31/12/1899 |
@from_timestamp | -3600 | 01/01/1970 |
@from_timestamp | 82800 | 02/01/1970 |
@from_timestamp | 169200 | 03/01/1970 |
@from_timestamp | 1621026306 | 14/05/2021 |
@age | -2209078814 | 70 |
@age | -2209078814 | 121 |
@age | -3600 | 0 |
@age | -3600 | 51 |
@age | 82800 | 0 |
@age | 82800 | 51 |
@age | 169200 | 51 |
Documentation is available in the datetime.dl file.