Opened 17 years ago
Closed 17 years ago
#4856 closed defect (bug) (invalid)
Timezone issues
Reported by: | Rauchg | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
I'm experiencing some issues with Wordpress timezone handling.
If we have a look at the current_time function, we'll see that when called with the 'timestamp' parameter it returns time() plus the GMT offset.
else $d = time() + (get_option('gmt_offset') * 3600);
However, if time() is not really returning the number of seconds till GMT, but to the timezone set in the server computer, it returns an incorrect value.
Test code as follows.
My timezone is GMT - 3. GMT for the example is 00:58:05
echo current_time('mysql'); echo date('Y-d-m H:i:s', current_time('timestamp')); // will return // 2007-08-28 21:58:05 (GMT -3: correct) // 2007-28-08 18:58:05 (GMT -6!)
The problem has been solved by resetting the TZ enviroment variable.
putenv('TZ='); echo current_time('mysql'); echo date('Y-d-m H:i:s', current_time('timestamp')); // returns // 2007-08-28 22:02:56 (GMT -3) // 2007-28-08 22:02:56 (GMT -3)
My setup:
guillermo-rauchs-computer:~ guillermo$ php -v PHP 5.2.2 (cli) (built: May 4 2007 17:56:56)
guillermo-rauchs-computer:~ guillermo$ uname -a Darwin guillermo-rauchs-computer.local 8.10.1 Darwin Kernel Version 8.10.1: Wed May 23 16:33:00 PDT 2007; root:xnu-792.22.5~1/RELEASE_I386 i386 i386
Using latest trunk
Haven't reproduced this in more computers. Can anyone do so?
Change History (5)
#2
@
17 years ago
This also came to my attention while developing a plugin.
Hope someone can shed some light on this.
#3
in reply to:
↑ description
@
17 years ago
Replying to Rauchg:
However, if time() is not really returning the number of seconds till GMT, but to the timezone set in the server computer, it returns an incorrect value.
This should not happen. Time is absolute, and time() should always return the current time, measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). That number of seconds does not change depending on what time zone you're in, it is an absolute figure for any given moment.
So, if time() gives you a wrong answer, then you have your server set to the incorrect time or PHP configured incorrectly or something else is wrong.
I recommend closing this as wontfix. This is a PHP or server configuration issue, not a WordPress issue.
#4
@
17 years ago
Also, this:
echo current_time('mysql'); echo date('Y-d-m H:i:s', current_time('timestamp')); // will return // 2007-08-28 21:58:05 (GMT -3: correct) // 2007-28-08 18:58:05 (GMT -6!)
Shows that the time on your server is set wrong. current_time('mysql') should have given you the UTC/GMT time, not GMT-3. Your "correct" mark is actually incorrect.
Linux systems, to pick a normal unix system, should always have their internal clocks set to UTC/GMT. The timezone is dealt with in the operating system, the computer clock is running on UTC/GMT.
I've been working on a plugin that uses current_time() and my beta testers have been having problems. I haven't been able to confirm this is the exact problem, but I'm 99% sure it is.