[drupal-devel] [bug] function format_date uses gmdate() incorrectly

thehunmonkgroup drupal-devel at drupal.org
Sun Sep 4 04:21:14 UTC 2005


Issue status update for 
http://drupal.org/node/29681
Post a follow up: 
http://drupal.org/project/comments/add/29681

 Project:      Drupal
 Version:      cvs
 Component:    base system
 Category:     bug reports
 Priority:     normal
 Assigned to:  thehunmonkgroup
 Reported by:  thehunmonkgroup
 Updated by:   thehunmonkgroup
 Status:       patch (code needs review)

i'm fairly certain that my logic is correct here.  the php doc on
gmdate() is not totally clear, but i think that if you read it over
closely, you'll see that it's the other way around--gmdate() is
actually the one that adjusts the timestamp passed.  i would recommend
writing some short scripts to test out how gmdate() and date() actually
operate(that's what i had to do!)--i think you'll see that what happens
is gmdate() takes the timestamp passed, applies the server timezone
offset, and returns the (formatted) result as GMT.  that's what my
tests have shown, and for the format_date function, this operation is
incorrect--the goal of the function is to simply make the timestamp
passed into a human-readable date.  no adjustment is necessary.




thehunmonkgroup



Previous comments:
------------------------------------------------------------------------

Thu, 25 Aug 2005 22:04:51 +0000 : thehunmonkgroup

Attachment: http://drupal.org/files/issues/format_date.patch (817 bytes)

function format_date in common.inc is using gmdate() incorrectly.  the
function is trying to format a local timestamp, and GMT conversion is
incorrect in this case.  date() should be used instead.  bug also
exists in 4.6, and this patch should apply there, too.  haven't checked
the earlier versions of drupal...




------------------------------------------------------------------------

Sat, 27 Aug 2005 04:47:39 +0000 : thehunmonkgroup

switching to patch status




------------------------------------------------------------------------

Sat, 03 Sep 2005 23:05:37 +0000 : clydefrog

Are you sure about the logic here? I've tried to fix timezone issues
before, and I always get confused. My reading of the documentation
makes me think your patch is wrong:


If the timestamp has already been converted to a localized time, then
gmdate() should be used because gmdate() does no timezone adjustments
(it does not care what PHP's timezone settings are). Using date() is
incorrect because it does care what PHP's timezone settings are.







More information about the drupal-devel mailing list