mclements / souffle-datetime

Date-time library for Souffle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C date-time functions for Souffle

NOTE: Development of these functions has been moved to souffle-lib.

Introduction

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-36000
@to_day828001
@to_day1692002
@to_day162102630618761
@to_date-22090788141899-12-31
@to_date-36001970-01-01
@to_date828001970-01-02
@to_date1692001970-01-03
@to_date16210263062021-05-14
@to_date_time-22090788141899-12-31 00:00:00
@to_date_time-36001970-01-01 00:00:00
@to_date_time828001970-01-02 00:00:00
@to_date_time1692001970-01-03 00:00:00
@to_date_time16210263062021-05-14 23:05:06
@from_timestamp-220907881431/12/1899
@from_timestamp-360001/01/1970
@from_timestamp8280002/01/1970
@from_timestamp16920003/01/1970
@from_timestamp162102630614/05/2021
@age-220907881470
@age-2209078814121
@age-36000
@age-360051
@age828000
@age8280051
@age16920051

Documentation is available in the datetime.dl file.

About

Date-time library for Souffle

License:Universal Permissive License v1.0


Languages

Language:Makefile 57.1%Language:M4 42.9%