#37440 closed defect (bug) (fixed)
current_time function outputs local time when it should output GMT time
Reported by: | bynicolas | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.1 | Priority: | normal |
Severity: | normal | Version: | 4.5.3 |
Component: | Date/Time | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
on line 68 when $gmt is true, the function returns local time by using date( $type ) when it should be using gmdate( $type )
Attachments (2)
Change History (13)
#2
follow-up:
↓ 3
@
8 years ago
Hi @bynicolas, welcome to Trac!
Line 68 looks correct to me as is. WordPress works with dates in UTC internally, see wp-settings.php.
#3
in reply to:
↑ 2
@
8 years ago
Hi @SergeyBiryukov, you are right, I didn't see that setting for the UTC timezone.
But wouldn't it be better to still use gmdate(). If for any reason the default timezone was changed by a user, then current_time( 'format', true) wouldn't return the GMT time (the expected value) since date() only formats a local time and would then be affected by date_default_timezone_set() change.
#5
@
6 years ago
I agree with a switch to gmdate()
, since implied UTC
context can be affected by plugins and is unreliable.
However all of date()
use needs to be switched, and the function is very very broken as it is. We need to be moving towards deprecating it altogether, but I will look into if functionality can be fixed up a bit.
#7
@
6 years ago
- Keywords has-unit-tests added
Added a unit test.
The function is still thoroughly broken, but one step (and unit test) at a time. :)
changed date function to gmdate as gmt is true.