Make WordPress Core


Ignore:
Timestamp:
11/01/2014 03:23:15 AM (10 years ago)
Author:
boonebgorges
Message:

Introduced dayofweek_iso time param for WP_Date_Query.

The initial dayofweek param sets day 1 to Sunday. This is out of step with
ISO standards, which calls Monday day 1. To maintain backward compatibility
with the existing parameter, we introduce the new dayofweek_iso for the
new, more compliant param.

Props mboynes.
Fixes #28063.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/date.php

    r29938 r30142  
    6161     * @var array
    6262     */
    63     public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'hour', 'minute', 'second' );
     63    public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second' );
    6464
    6565    /**
     
    6868     * @since 3.7.0
    6969     * @since 4.0.0 The $inclusive logic was updated to include all times within the date range.
     70     * @since 4.1.0 Introduced 'dayofweek_iso' time type parameter.
    7071     * @access public
    7172     *
     
    117118     *             @type int          $dayofyear Optional. The day number of the year. Default empty. Accepts numbers 1-366.
    118119     *             @type int          $day       Optional. The day of the month. Default empty. Accepts numbers 1-31.
    119      *             @type int          $dayofweek Optional. The day number of the week. Default empty. Accepts numbers 1-7.
     120     *             @type int          $dayofweek Optional. The day number of the week. Default empty. Accepts numbers 1-7 (1 is Sunday).
     121     *             @type int          $dayofweek_iso Optional. The day number of the week (ISO). Default empty.
     122     *                       Accepts numbers 1-7 (1 is Monday).
    120123     *             @type int          $hour      Optional. The hour of the day. Default empty. Accepts numbers 0-23.
    121124     *             @type int          $minute    Optional. The minute of the hour. Default empty. Accepts numbers 0-60.
     
    310313        // Days per week.
    311314        $min_max_checks['dayofweek'] = array(
     315            'min' => 1,
     316            'max' => 7
     317        );
     318
     319        // Days per week.
     320        $min_max_checks['dayofweek_iso'] = array(
    312321            'min' => 1,
    313322            'max' => 7
     
    728737            $where_parts[] = "DAYOFWEEK( $column ) $compare $value";
    729738
     739        if ( isset( $query['dayofweek_iso'] ) && $value = $this->build_value( $compare, $query['dayofweek_iso'] ) )
     740            $where_parts[] = "WEEKDAY( $column ) + 1 $compare $value";
     741
    730742        if ( isset( $query['hour'] ) || isset( $query['minute'] ) || isset( $query['second'] ) ) {
    731743            // Avoid notices.
Note: See TracChangeset for help on using the changeset viewer.