diff --git a/wp-includes/template-functions-general.php b/wp-includes/template-functions-general.php index d7a6abf4d6..35d7619296 100644 --- a/wp-includes/template-functions-general.php +++ b/wp-includes/template-functions-general.php @@ -320,10 +320,13 @@ function get_calendar($daylength = 1) { $w = ''.intval($HTTP_GET_VARS['w']); } $time_difference = get_settings('time_difference'); + $add_hours = intval($time_difference); + $add_minutes = intval(60 * ($time_difference - $add_hours)); + $wp_posts_post_date_field = "DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)"; // Let's figure out when we are if (!empty($monthnum) && !empty($year)) { - $thismonth = ''.intval($monthnum); + $thismonth = ''.zeroise(intval($monthnum), 2); $thisyear = ''.intval($year); } elseif (!empty($w)) { // We need to get the month from MySQL @@ -336,23 +339,23 @@ function get_calendar($daylength = 1) { if (strlen($m) < 6) { $thismonth = '01'; } else { - $thismonth = ''.intval(substr($m, 4, 2)); + $thismonth = ''.zeroise(intval(substr($m, 4, 2), 2)); } } else { - $thisyear = intval(date('Y', time()+($time_difference * 3600))); - $thismonth = intval(date('m', time()+($time_difference * 3600))); + $thisyear = gmdate('Y', current_time('timestamp')); + $thismonth = gmdate('m', current_time('timestamp')); } $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); // Get the next and previous month and year with at least one post - $previous = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year + $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $tableposts - WHERE post_date < '$thisyear-$thismonth-01' + WHERE $wp_posts_post_date_field < '$thisyear-$thismonth-01' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); - $next = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year + $next = $wpdb->get_row("SELECT DISTINCT MONTH($wp_posts_post_date_field) AS month, YEAR($wp_posts_post_date_field) AS year FROM $tableposts WHERE post_date > '$thisyear-$thismonth-01' AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) @@ -401,11 +404,11 @@ function get_calendar($daylength = 1) {