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

Otto otto at ottodestruct.com
Thu Feb 11 14:40:18 UTC 2010

I do not like the "fix" that has been employed, because as you've
noticed, it invalidates all the calls to date and other such time
related functions. Everything now gives GMT time by default. Annoying,
IMO. Especially as the only purpose of this "fix" is to create
consistent behavior across PHP 4 (which does not support timezones
properly) and PHP 5 (which does).

In other words, "date" in WordPress now behaves incorrectly. But it's
consistently incorrect, so that's somehow "okay". :rolleyes:

So, if you're using PHP 5, I would simply call
date_default_timezone_set( get_option('timezone_string') ); yourself,
to correct this error. date and similar functions that are supposed to
return the local time will then do so, after you do that.

Sent from Memphis, TN, United States

On Wed, Feb 10, 2010 at 8:50 PM, Luke Gallagher <notfornoone at gmail.com> wrote:
> 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:
> http://core.trac.wordpress.org/changeset/12727
> 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
> like:
> 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.
> thanks,
> Luke
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list