Parse RRULE statements, and generate occurrences.
Execute postgres-rrule.sql
in your database:
psql -X -f postgres-rrule.sql
Or
make all
Requires pgTAP
and pg_resolve
. First let's install those from CPAN.
$ sudo cpan TAP::Parser::SourceHandler::pgTAP
Now you can run the tests with
$ make all test
This repo is a fork of Matthew Schinckel's original repo. I have cleaned up some functions and fixed a few tests. There are still a few broken tests that I couldn't fix. If you can lend a help, please create an issue on this repo.
We create a table (in a newly created _rrule
schema) called RRULE
to generate start dates from rule criteria. The table constraints enforce the validity of dates in the table.
All of the types and functions are created in that schema.
These operators have been implemented.
| Operator | Description | Notes | Result |
|-|-|-|
| =
| equal | All parameters match | boolean
|
| <>
| not equal | Any parameters don't match | boolean
|
| @>
| contains rrule
| All occurrences generated by second rule would also be generated by first rule | boolean
|
| <@
| contained by rrule
| | boolean
|
None of these operators have been implemented.
| Operator | Description | Notes | Result |
|-|-|-|
| =
| equal | True if all occurrences equal. | boolean
|
| <>
| not equal| True if any occurrences occur in one and not the other. | boolean
|
| <
| less than | True if all last occurrence of left is before first occurrence of right | boolean
|
| >
| greater than | | boolean
|
| <=
| less than or equal | Not sure about this one | boolean
|
| >=
| greater than or equal | Not sure about this one | boolean
|
| @>
| contains timestamp
| Is this timestamp
an occurence? | boolean
|
| @>
| contains rruleset
| Are all occurrences of RHS in LHS's occurrence list? | boolean
|
| <@
| timestamp
is contained by | | boolean
|
| <@
| rruleset is contained by | | boolean
|
| &&
| overlap (have instances in common) | May also compare with tsrange
/daterange
? | boolean
|
| <<
| strictly left of | | boolean
|
| >>
| strictly right of | | boolean
|
| &<
| does not extend to the right of | | boolean
|
| &>
| does not extend to the left of | | boolean
|
| -|-
| is adjacent to | | boolean
|
| +
| union | 2nd operand may be timestamp
, rrule
or rruleset
| rruleset
|
| *
| intersection | 2nd operand may be rrule
or rruleset
| rruleset
|
| -
| difference | 2nd operand may be timestamp
, rrule
or rruleset
| rruleset
|
In the case of the rrule
functions, there is also a second required argument of type timestamp
, which is the "dtstart"
argument of a rruleset
. There is also a form for each rrule
-accepting function that accepts a text
value, and parses it.
The functions parse_rrule(text)
, and is_finite(rrule/text)
have been implemented.
Function | Return Type | Description | Example | Result |
---|---|---|---|---|
parse_rrule(text) |
rrule |
Parse an RRULE statement | ||
first(rrule, timestamp) |
timestamp |
The first occurrence | ||
first(rruleset) |
timestamp |
The first occurrence | ||
last(rrule, timestamp) |
timestamp |
The last occurrence | ||
last(rruleset) |
timestamp |
The last occurrence | ||
occurrences(rrule, timestamp) |
timestamp[] |
All occurrences | ||
occurrences(rruleset) |
timestamp[] |
All occurrences | ||
occurrences(rrule, timestamp, tsrange) |
timestamp[] |
All occurrences between lower(tsrange) and upper(tsrange) |
||
occurrences(rruleset, tsrange) |
timestamp[] |
All occurrences between lower(tsrange) and upper(tsrange) |
||
after(rrule, timestamp, timestamp) |
timestamp[] |
All occurrences after timestamp |
||
after(rruleset, timestamp) |
timestamp[] |
All occurrences after timestamp |
||
before(rrule, timestamp, timestamp) |
timestamp[] |
All occurrences before timestamp |
||
before(rruleset, timestamp) |
timestamp[] |
All occurrences before timestamp |
||
is_finite(rrule) |
boolean |
Is there a finite number of occurrences? | ||
is_finite(rruleset) |
boolean |
Is there a finite number of occurrences? |