Make WordPress Core


Ignore:
Timestamp:
05/07/2010 05:01:29 AM (16 years ago)
Author:
nacin
Message:

Fix start of week and SQL WEEK handling. props mdawaffe, fixes #10397.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r14495 r14499  
    193193    $day = mktime( 0, 0, 0, $md, $mm, $my ); // The timestamp for mysqlstring day.
    194194    $weekday = date( 'w', $day ); // The day of the week from the timestamp
    195     $i = 86400; // One day
    196195    if ( !is_numeric($start_of_week) )
    197196        $start_of_week = get_option( 'start_of_week' );
    198197
    199198    if ( $weekday < $start_of_week )
    200         $weekday = 7 - $start_of_week - $weekday;
    201 
    202     while ( $weekday > $start_of_week ) {
    203         $weekday = date( 'w', $day );
    204         if ( $weekday < $start_of_week )
    205             $weekday = 7 - $start_of_week - $weekday;
    206 
    207         $day -= 86400;
    208         $i = 0;
    209     }
    210     $week['start'] = $day + 86400 - $i;
    211     $week['end'] = $week['start'] + 604799;
    212     return $week;
     199        $weekday += 7;
     200
     201    $start = $day - 86400 * ( $weekday - $start_of_week ); // The most recent week start day on or before $day
     202    $end = $start + 604799; // $start + 7 days - 1 second
     203    return compact( 'start', 'end' );
    213204}
    214205
     
    41694160}
    41704161
     4162/**
     4163 * Returns a MySQL expression for selecting the week number based on the start_of_week option.
     4164 *
     4165 * @internal
     4166 * @since 3.0.0
     4167 * @param string $column
     4168 * @return string
     4169 */
     4170function _wp_mysql_week( $column ) {
     4171    switch ( $start_of_week = (int) get_option( 'start_of_week' ) ) {
     4172    default :
     4173    case 0 :
     4174        return "WEEK( $column, 0 )";
     4175    case 1 :
     4176        return "WEEK( $column, 1 )";
     4177    case 2 :
     4178    case 3 :
     4179    case 4 :
     4180    case 5 :
     4181    case 6 :
     4182        return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 0 )";
     4183    }
     4184}
     4185
    41714186?>
Note: See TracChangeset for help on using the changeset viewer.