Opened 11 years ago
Closed 11 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: |
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)
Change History (10)
#1
follow-up:
↓ 2
@
11 years ago
- Keywords needs-patch removed
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
#2
in reply to:
↑ 1
@
11 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
@
11 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
@
11 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.
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.