WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#25555 closed defect (bug) (duplicate)

get_comment_time('c') uses UTC timezone only

Reported by: raubvogel Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.6.1
Component: Date/Time Keywords: has-patch
Focuses: Cc:
PR Number:

Description

Calling

get_comment_time('c')

(wordpress\wp-includes\comment-template.php:629) returns date and time like 2013-10-10T12:22:56+00:00. Date and time values are correct, i. e., it considers the timezone set in Wordpress. But +00:00 is wrong! In my case it has to be +02:00 because I set the timezone to CEST (Berlin, GMT+2).

I could trace the issue: get_comment_time('c') calls

date_i18n('c')

(wordpress\wp-includes\functions.php:84) which calls PHP’s date() by

$j = @$datefunc( $dateformatstring, $i );

(wordpress\wp-includes\functions.php:138) at the end (@$datefunc = date()). But date() depends on PHP’s date_default_timezone_set() which is set by wordpress/wp-settings.php:36 to

// WordPress calculates offsets from UTC.
date_default_timezone_set( 'UTC' );

Therefore date() considers not the timezone set in Wordpress. Don’t know how to patch this. It’s possible that more code is affected than the shown one.

Attachments (1)

functions.php.patch (2.4 KB) - added by raubvogel 6 years ago.
Fix

Download all attachments as: .zip

Change History (10)

#1 follow-up: @johnbillion
6 years ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

date_i18n() doesn't take into account the site's timezone because it's a localisation function. The function is intended to format the date string according to the site's locale.

To get the date in the site's specified timezone you should use get_date_from_gmt(). See the example given in the comments on #25331.

#2 in reply to: ↑ 1 @raubvogel
6 years ago

Replying to johnbillion:

date_i18n() doesn't take into account the site's timezone because it's a localisation function. The function is intended to format the date string according to the site's locale.

To get the date in the site's specified timezone you should use get_date_from_gmt(). See the example given in the comments on #25331.

I do not know if date_i18n() is implemented correctly. Anyway, look at get_comment_time('c') please. The result is deftly not correct. You can see this if you just take the default Twentythirteen theme. get_comment_time('c') is used in comments and outputs a wrong <time datetime="2013-10-10T12:22:56+00:00"> tag. Please look at wordpress\wp-includes\comment-template.php:1684 – it’s used in the core. Finally something is wrong. Can You please reopen the ticket?

#3 @raubvogel
6 years ago

  • Keywords needs-patch added
  • Resolution duplicate deleted
  • Status changed from closed to reopened
  • Summary changed from get_comment_time('c') and date_i18n('c') uses UTC timezone only to get_comment_time('c') uses UTC timezone only

#4 @raubvogel
6 years ago

Another easy test shows that there is something wrong: in the admin area goto Settings -> General -> Date Format -> Custom and type "c" (without ""). Then Save Changes. Output in the date preview next to the Custom field is like 2013-10-11T12:48:05+00:00. The time zone part "+00:00" is wrong; has to be "+02:00" for my time zone (Berlin). Date and time part are adjusted correctly according the time zone.

#5 follow-up: @Jayjdk
6 years ago

Related or duplicate of #20973?

#6 in reply to: ↑ 5 @raubvogel
6 years ago

Replying to Jayjdk:

Related or duplicate of #20973?

I think You are right. Can I mark #20973 as a duplicate of my #25555? I want to provide a fix/patch in #25555. Or do I have to provide the fix in #20973?

@raubvogel
6 years ago

Fix

#7 @raubvogel
6 years ago

  • Keywords has-patch added; needs-patch removed

#8 @raubvogel
6 years ago

#20973 was marked as a duplicate.

#9 @raubvogel
6 years ago

  • Resolution set to duplicate
  • Status changed from reopened to closed

Duplicate of #20973.

Note: See TracTickets for help on using tickets.