DateSql final class
Minn\Query\DateSql · public/minn/src/Minn/Query/DateSql.php · 303 lines
The WHERE fragment of a date query in the reference's shape: before and after bounds as full datetimes (inclusive bounds close the day), the date parts as MySQL functions compared or listed, groups joined by their relation, columns validated against the known date columns.
Constants and properties
| private | COLUMNS = array ( 'posts' => array ( 0 => 'post_date', 1 => 'post_date_gmt', 2 => 'post_modified', 3 => 'post_modified_gmt', ), 'comments' => array ( 0 => 'comment_date', 1 => 'comment_date_gmt', ), 'users' => array ( 0 => 'user_registered', ), 'blogs' => array ( 0 => 'registered', 1 => 'last_updated', ), ) | |
| private | PART_ORDER = array ( 0 => 'year', 1 => 'month', 2 => 'monthnum', 3 => 'week', 4 => 'w', 5 => 'dayofyear', 6 => 'day', 7 => 'dayofweek', 8 => 'dayofweek_iso', 9 => 'hour', 10 => 'minute', 11 => 'second', ) | |
| private | RANGES = array ( 'dayofyear' => array ( 0 => 1, 1 => 366, ), 'dayofweek' => array ( 0 => 1, 1 => 7, ), 'dayofweek_iso' => array ( 0 => 1, 1 => 7, ), 'month' => array ( 0 => 1, 1 => 12, ), 'week' => array ( 0 => 1, 1 => 53, ), 'day' => array ( 0 => 1, 1 => 31, ), 'hour' => array ( 0 => 0, 1 => 23, ), 'minute' => array ( 0 => 0, 1 => 59, ), 'second' => array ( 0 => 0, 1 => 59, ), ) | The ranges a date part is checked against, in the order the reference reports them (week's top depends on the year). |
| private | ?Closure $validColumns | |
| private | readonly array $tables | Promoted from the constructor. |
| private | readonly string $defaultColumn | Promoted from the constructor. |
| private | readonly int $startOfWeek | Promoted from the constructor. |
Public
| new | __construct(array $tables, string $defaultColumn = 'post_date', int $startOfWeek = 1)# |
| |||
| static | week(string $column, int $startOfWeek): string# | The week of a column as the reference counts it from the site's first day of the week. | |||
| static | validate(array $clause): bool# | Whether a clause's date values are valid, with a notice for each part out of range (week up to the given year's ISO weeks, 53 without one) and for a month and day that make no date (in a leap year when no year is given, and only once every part is in range); before and after given as parts are checked too (probes query-clauses, query-clause-internals). An empty clause is not valid. | |||
| method | sanitize(array $queries, array $defaults): array# | Sanitises to the reference's shape: every level carries column, compare and relation. | |||
| static | isFirstOrder(array $query): bool# | Whether a date query is one clause rather than a group of them. | |||
| method | validateColumn(string $column): string# | A column name as "table.column", the default for anything unknown. | |||
| method | checkColumnsWith(Closure $validColumns): self# | Has the valid columns pass through a filter (WP_Date_Query hands it date_query_valid_columns). | |||
| method | build(array $queries): string# | The WHERE fragment for a date query. | |||
| method | forQuery(array $queries, int $depth): array# | A query or group as the reference's get_sql_for_query returns it, indented for its depth. @return array{join: string, where: string} @return array{join: string, where: string} | |||
| method | clauseParts(array $clause): array# | One clause's pieces, before they are joined: the bounds, the date parts in order (a part whose value builds to nothing, or to 0, is left out), then the time. @return list<string> | |||
| static | buildValue(string $compare, mixed $value): string|int|false# | A value as the comparison wants it (build_value): a list of numbers for IN, exactly two for BETWEEN, one number otherwise; false when the value does not fit. | |||
| static | buildTime(string $column, string $compare, mixed $hour, mixed $minute, mixed $second): string|false# | The time of day (build_time_query): listed or ranged parts each on their own; a single part by its function; an hour with a second and no minute not at all; otherwise the parts as one decimal, DATE_FORMAT( col, '%H.%i%s' ). False when no part is given. | |||
| static | datetime(mixed $value, bool $endOfUnit): string# | A full datetime from a string or a parts array. A string as precise as a year, a month, a day or a minute is read as those parts, so an end bound reaches the end of its unit; any other string is read as a time in the site's zone. Missing parts start (or end) the unit. | |||
| static | compare(string $compare): string# | A comparison upper-cased, = for anything the reference does not know. |
Internals 4
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | validDate(array $clause): bool# | Whether a clause's month and day make a date, in its year or a leap year; a notice names them when they do not. |
| private | partExpressions(string $column, array $clause): array# | The date parts a clause gives, each as its SQL expression; monthnum and w stand in for month and week only when those are not given. @return array<string, string> @return array<string, string> |
| private | group(array $queries, int $depth): string# | |
| private | clause(array $clause): string# | One clause as the reference writes it: its pieces, more than one joined by AND inside parentheses. |
Nothing matches.