HasFilterDate
This trait defines the date filter helpers.
Configure
Defines the 'filters' property in the model (Documents) definition.
Models::PLACES => fn( ContainerInterface $container ) => new Documents
(
$container ,
Collections::PLACES ,
[
...
AQL::FILTERS =>
[
Prop::CREATED => FilterType::DATE ,
]
...
Usage
Use a date time strings in ISO 8601 format value to filter the query result.
?filter={ "key":"created" , "val":"2024-12-21T10:00:00" }
// FILTER doc.created == "2024-12-21T10:00:00"
Use the "now" attribute to use the current date value.
?filter={ "key":"created" , "op":"le" , "val":"now" }
// FILTER doc.created <= DATE_ISO8601(DATE_NOW())
Use the "cts" attribute to use the current timestamp value.
?filter={ "key":"created" , "val":"cts" }
// FILTER doc.created == DATE_NOW() (current timestamp)
Use the "tz" attribute to specify the local timezone of the value and convert it in the Zulu time (UTC).
?filter={ "key":"created" , "op":"gt" , "val":"2024-12-21T10:00:00" , "tz":"Europe/Paris" }
// FILTER doc.created <= DATE_LOCALTOUTC("2024-12-21T10:00:00","Europe/Paris")
Functions*
Alters the document attribute with the AQL DATE_DAY() method and use the day part of date as number.
?filter={ "key":"date" , "val":12 , "alt":"d" }
// FILTER DATE_DAY(doc.date) == 12
Use the "dw" alter attribute to transform the document property with the DATE_DAYOFWEEK() method and use the weekday number of date : 0 – Sunday / 1 – Monday / 2 – Tuesday / 3 – Wednesday / 4 – Thursday / 5 – Friday / 6 – Saturday
?filter={ "key":"date" , "val":2 , "alt":"dw" }
// FILTER DATE_DAYOFWEEK(doc.date) == 2
Use the "dy" alter attribute to transform the document property with the DATE_DAYOFYEAR() method and use the day of year number of date : The return values range from 1 to 365, or 366 in a leap year respectively.
?filter={ "key":"date" , "val":242 , "alt":"dy" }
// FILTER DATE_DAYOFYEAR(doc.date) == 242
Table of Contents
Methods
- prepareFilterDate() : string
- Prepares the filter clause with a Date attribute.
- prepareFilterDateBound() : string
- Resolves a single date bound (value or `between` min/max) to AQL.
- prepareFilterDateValue() : string
- Prepares the value of a date attribute in a filter clause.
Methods
prepareFilterDate()
Prepares the filter clause with a Date attribute.
protected
prepareFilterDate([array<string|int, mixed> $init = [] ][, array<string|int, mixed>|null &$binds = null ][, string $doc = AQL::DOC ]) : string
Parameters
- $init : array<string|int, mixed> = []
- $binds : array<string|int, mixed>|null = null
- $doc : string = AQL::DOC
Tags
Return values
stringprepareFilterDateBound()
Resolves a single date bound (value or `between` min/max) to AQL.
protected
prepareFilterDateBound(mixed $value, array<string|int, mixed> $init[, array<string|int, mixed>|null &$binds = null ]) : string
The magic values resolve to AQL date functions (now/null → DATE_ISO8601(DATE_NOW()),
cts → DATE_NOW(), tomorrow/yesterday); any other value is bound, and
converted from the request timezone (tz) to UTC when one is supplied.
Parameters
- $value : mixed
-
The bound value (null means "now").
- $init : array<string|int, mixed>
-
The filter init (reads
tz). - $binds : array<string|int, mixed>|null = null
-
The bind variables, populated by reference.
Tags
Return values
stringprepareFilterDateValue()
Prepares the value of a date attribute in a filter clause.
protected
prepareFilterDateValue([string|array<string|int, mixed>|null $init = [] ][, array<string|int, mixed>|null &$binds = null ]) : string
Parameters
- $init : string|array<string|int, mixed>|null = []
- $binds : array<string|int, mixed>|null = null