Errors in JDate construct

This forum is for reporting bugs in Joomla!. Please don't report problems with extensions in here.
Locked
kdevine
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Thu Mar 02, 2006 8:38 pm
Location: Baltimore, MD

Errors in JDate construct

Post by kdevine » Sat Dec 15, 2007 6:55 pm

I think there are few bugs in the construct method of JDate.

First, the regex in the second preg_match looks like it should be catching strings in MySQL Datetime format and if you make a change in the whitespace match it does:

Code: Select all

- if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~",$date,$matches))
+ if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})[T\s](\\d{2}):(\\d{2}):(\\d{2})(.*)~",$date,$matches))
The second problem is that it is using gmmktime which has a bug in certain versions of PHP. It returns the wrong time.
http://bugs.php.net/bug.php?id=30096
The thread says the bug has been fixed, in fact it is in the changlog for PHP 5.1.0
http://www.php.net/ChangeLog-5.php
but with previous versions of PHP gmmktime will not be correct.

Is gmmktime even the right function to be using here? That function accepts a GM Date and returns a Unix time in the server local time. I think JDate is supposed to set it's $_date property to a GM Time which means it should be changed this way...

Code: Select all

- $this->_date = gmmktime($matches[4],$matches[5],$matches[6],$matches[2],$matches[3],$matches[1]);
+ $this->_date = mktime($matches[4],$matches[5],$matches[6],$matches[2],$matches[3],$matches[1]) - $this->serverOffset();
Last edited by kdevine on Sat Dec 15, 2007 10:43 pm, edited 1 time in total.

User avatar
pvh123
Joomla! Ace
Joomla! Ace
Posts: 1156
Joined: Wed Oct 05, 2005 7:25 am
Location: Emmen

Re: Errors in JDate construct

Post by pvh123 » Wed Dec 19, 2007 9:26 am

kdevine wrote:
Is gmmktime even the right function to be using here? That function accepts a GM Date and returns a Unix time in the server local time. I think JDate is supposed to set it's $_date property to a GM Time which means it should be changed this way...
If you use GMT that would give the same article publishing time all over the world, is it not? A bit difficult if the publishing of your articles is based on the local time. For instance all articles in Holland would have a publishing time 2 hours earlier.
I have seen posts where this would be a very big problem. On the other hand using GMTthe DLT (daylight saving time) problem would be gone than as well :)
Note: Sending me private messages for personal support, without this been requested, would lead to ignoring any of your posts in future!

kdevine
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Thu Mar 02, 2006 8:38 pm
Location: Baltimore, MD

Re: Errors in JDate construct

Post by kdevine » Thu Dec 20, 2007 12:48 pm

Here is my reasoning for converting the datetime to GMT during construct...

The server might be in a different time zone than the user. The PHP date() function will return the local server time. Then if the user sets a location in global config, the offset will be from their server time not GMT. But, if you convert date (local server time) to GMT during construct then use the offset from global config with toMySQL or toFormat then the date will be the time zone the user chooses.

Regardless, gmmktime cannot be used since it returns the wrong time in PHP versions previous to 5.1.0.

User avatar
pvh123
Joomla! Ace
Joomla! Ace
Posts: 1156
Joined: Wed Oct 05, 2005 7:25 am
Location: Emmen

Re: Errors in JDate construct

Post by pvh123 » Thu Dec 20, 2007 8:10 pm

`Thanks for your explanation.
Note: Sending me private messages for personal support, without this been requested, would lead to ignoring any of your posts in future!

User avatar
masterchief
Joomla! Hero
Joomla! Hero
Posts: 2247
Joined: Fri Aug 12, 2005 2:45 am
Location: Brisbane, Australia
Contact:

Re: Errors in JDate construct

Post by masterchief » Thu Dec 20, 2007 10:42 pm

The other problem we have is that true (or maybe what we think were true) dates are being pushed into JDate for formatting.  Trouble is they are then being double offset, eg, JHTML::_( 'date' ) runs the date through the JDate formatter but that's already been saved in GMT.  My initial thoughts are to try and make JDate more agnostic and you must explicitly do something to ->toGMT or ->fromGMT type calls.
Andrew Eddie - Tweet @AndrewEddie
<><
http://eddify.me
http://www.kiva.org/team/joomla - Got Joomla for free? Pay it forward and help fight poverty.

User avatar
pvh123
Joomla! Ace
Joomla! Ace
Posts: 1156
Joined: Wed Oct 05, 2005 7:25 am
Location: Emmen

Re: Errors in JDate construct

Post by pvh123 » Fri Dec 21, 2007 6:30 am

The offset to GMT is actually a good idea. All one needs to do is setup a global var with the time difference to GMT and use that as a offset in the code. But that would need very good instructions to the devs developing extensions.

It is always tricky because you also depend very much on your provider hosting  your website. I had this problem before when I was writing  ASP functions for my website and when I had the date functions right, my host decided that he was going to use the USA date rather than the Dutch. Therefore all my dates where up the creek.
Note: Sending me private messages for personal support, without this been requested, would lead to ignoring any of your posts in future!


Locked

Return to “Joomla! 1.5 Bug Reporting”