Temporal operators
Description | CQL2 Operator | Resulting OData Operator |
---|---|---|
The subject is a temporal entity that occurs after the object | t_after |
gt |
The subject is a temporal entity that occurs before the object | t_before |
lt |
Beginning of a temporal entity. | t_begins |
ge |
End of a temporal entity. | t_ends |
le |
In [1]:
Copied!
from pygeocdse.evaluator import to_cdse
cql2_filter = {
"op": "and",
"args": [
{
"op": "t_after",
"args": [
{"property": "ContentDate/Start"},
{"timestamp": "2023-02-01T00:00:00Z"}
],
},
{
"op": "t_before",
"args": [
{"property": "ContentDate/Start"},
{"timestamp": "2023-02-28T23:59:59Z"}
],
},
],
}
print(to_cdse(cql2_filter))
from pygeocdse.evaluator import to_cdse
cql2_filter = {
"op": "and",
"args": [
{
"op": "t_after",
"args": [
{"property": "ContentDate/Start"},
{"timestamp": "2023-02-01T00:00:00Z"}
],
},
{
"op": "t_before",
"args": [
{"property": "ContentDate/Start"},
{"timestamp": "2023-02-28T23:59:59Z"}
],
},
],
}
print(to_cdse(cql2_filter))
ContentDate/Start gt 2023-02-01T00:00:00+00:00 and ContentDate/Start lt 2023-02-28T23:59:59+00:00
/tmp/ipykernel_2003/2737362975.py:23: DeprecationWarning: Parsing dates involving a day of month without a year specified is ambiguious and fails to parse leap day. The default behavior will change in Python 3.15 to either always raise an exception or to use a different default year (TBD). To avoid trouble, add a specific year to the input & format. See https://github.com/python/cpython/issues/70647. print(to_cdse(cql2_filter))
Please take note that the ISO format for dates in OData are internally handled, so users can express dates in CQL2 supported formats.
Intervals¶
Intervals are supported for a single property, they are limits inclusive by default, the op
has to be accurately tuned, i.e.
In [2]:
Copied!
from pygeocdse.evaluator import to_cdse
cql2_filter = {
"op": "and",
"args": [
{
"op": "t_after",
"args": [
{"property": "ContentDate/Start"},
{"interval": ["2023-02-01T00:00:00Z", "2023-02-01T23:59:59Z"]},
],
},
{
"op": "t_before",
"args": [
{"property": "ContentDate/End"},
{"interval": ["2023-02-28T00:00:00Z", "2023-02-28T23:59:59Z"]}
],
},
]
}
print(to_cdse(cql2_filter))
from pygeocdse.evaluator import to_cdse
cql2_filter = {
"op": "and",
"args": [
{
"op": "t_after",
"args": [
{"property": "ContentDate/Start"},
{"interval": ["2023-02-01T00:00:00Z", "2023-02-01T23:59:59Z"]},
],
},
{
"op": "t_before",
"args": [
{"property": "ContentDate/End"},
{"interval": ["2023-02-28T00:00:00Z", "2023-02-28T23:59:59Z"]}
],
},
]
}
print(to_cdse(cql2_filter))
ContentDate/Start gt 2023-02-01T00:00:00+00:00 and ContentDate/Start le 2023-02-01T23:59:59+00:00 and ContentDate/End ge 2023-02-28T00:00:00+00:00 and ContentDate/End lt 2023-02-28T23:59:59+00:00
/tmp/ipykernel_2003/1658964328.py:23: DeprecationWarning: Parsing dates involving a day of month without a year specified is ambiguious and fails to parse leap day. The default behavior will change in Python 3.15 to either always raise an exception or to use a different default year (TBD). To avoid trouble, add a specific year to the input & format. See https://github.com/python/cpython/issues/70647. print(to_cdse(cql2_filter))
Time deltas¶
ISO 8601 duration format is supported inside Time intervals, the interpreter will take care of converting datetimes.
Deltas are supported in both end
parameter of the interval:
In [3]:
Copied!
from pygeocdse.evaluator import to_cdse
cql2_filter = {
"op": "t_after",
"args": [
{"property": "ContentDate/Start"},
{"interval": ["2023-02-28T00:00:00Z", "PT4S"]},
],
}
print(to_cdse(cql2_filter))
from pygeocdse.evaluator import to_cdse
cql2_filter = {
"op": "t_after",
"args": [
{"property": "ContentDate/Start"},
{"interval": ["2023-02-28T00:00:00Z", "PT4S"]},
],
}
print(to_cdse(cql2_filter))
ContentDate/Start gt 2023-02-28T00:00:00+00:00 and ContentDate/Start le 2023-02-28T00:00:04+00:00
/tmp/ipykernel_2003/2317444080.py:11: DeprecationWarning: Parsing dates involving a day of month without a year specified is ambiguious and fails to parse leap day. The default behavior will change in Python 3.15 to either always raise an exception or to use a different default year (TBD). To avoid trouble, add a specific year to the input & format. See https://github.com/python/cpython/issues/70647. print(to_cdse(cql2_filter))
And in the start
parameter of the interval:
In [4]:
Copied!
from pygeocdse.evaluator import to_cdse
cql2_filter = {
"op": "t_after",
"args": [
{"property": "ContentDate/Start"},
{"interval": ["PT4S", "2023-02-28T00:00:00Z"]},
],
}
print(to_cdse(cql2_filter))
from pygeocdse.evaluator import to_cdse
cql2_filter = {
"op": "t_after",
"args": [
{"property": "ContentDate/Start"},
{"interval": ["PT4S", "2023-02-28T00:00:00Z"]},
],
}
print(to_cdse(cql2_filter))
ContentDate/Start gt 2023-02-27T23:59:56+00:00 and ContentDate/Start le 2023-02-28T00:00:00+00:00
/tmp/ipykernel_2003/1758570653.py:11: DeprecationWarning: Parsing dates involving a day of month without a year specified is ambiguious and fails to parse leap day. The default behavior will change in Python 3.15 to either always raise an exception or to use a different default year (TBD). To avoid trouble, add a specific year to the input & format. See https://github.com/python/cpython/issues/70647. print(to_cdse(cql2_filter))