Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 8 years ago

#11672 closed defect (bug) (fixed)

current_time() does not correctly retrun localized time

Reported by: hiromasa's profile hiromasa Owned by: nbachiyski's profile nbachiyski
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.9
Component: Date/Time Keywords:
Focuses: Cc:

Description

When you set you set timezone using a city name, current_time() function in functions.php does not return correct local time.

Cause:

When you get gmt_offset(), the wp_timezone_override_offset() hook offsets the timezone again after date_default_timezone_set sets the timezone (this happens only when timezone_string exists).

Example 1:

Your timezone is set to "Tokyo" (UTC+9), using the city name. wp_options will contain:

timezone_string	Asia/Tokyo
gmt_offset      ''

Code below will incorrectly retun UTC+9+9.

<?php echo date('Y-m-d H:i:s', current_time( 'timestamp' )); ?>

Example 2:

Your timezone is set to "UTC+9" (WordPress 2.9.1 RC1). wp_options will contain:

timezone_string	''
gmt_offset      9

Code below will correctly retun UTC+9.

<?php echo date('Y-m-d H:i:s', current_time( 'timestamp' )); ?>

Change History (5)

#2 @ryan
15 years ago

  • Component changed from General to Date/Time

#3 @ryan
15 years ago

  • Milestone changed from Unassigned to 3.0

#4 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.