[wp-hackers] current_time, time, date_default_timezone_set, UTC timezone

Luke Gallagher notfornoone at gmail.com
Thu Feb 11 04:41:50 UTC 2010

Ok trying one more time, again I am sorry for the resend.

I am trying to work out how date related functions should be used and
how that affects the development of plugins and plugins that use third
party libraries.

I am basing this from the latest checkout from SVN as the following
date/time related issues appear to be fixed:

From what I can tell it appears that to get the correct time one
should be using current_time('timestamp') instead of PHP's time. This
is because Wordpress sets the default timezone to UTC and current_time
offsets the time from what it finds in the gmt_offset setting.

Ok so now lets say I have created a plugin. Its purpose is to log
messages to a log file with a timestamp.

Obviously at this point generating a timestamp with PHP's date
function is going to be incorrect unless of course your timezone is
UTC +0. So to get the correct time I would use current_time, something
date('Y-m-d H:i:s'), current_time('timestamp')

This is all good, all I have to do is update my plugin with any calls
to date or time with current_time.

My question is what about if I use a third party library that makes
calls to time or date and this library is updated by the third party
from time to time so I don't want to modifiy it. How could one avoid a
scenario like this? Is there more to the date/time handling in
Wordpress that I could be missing?

One initial thought is to set the default timezone to the timezone set
in Wordpress settings before a function call from that library and
then set it back to UTC after.



More information about the wp-hackers mailing list