On Sat Dec 6 12:09 AM, Lester Caine wrote:
> Derick Rethans wrote:
> >> ( Slipping a date through DateTime and returning it DATE_W3C seems
> to
> >> be adding the correct daylight saving details so far and allowing 
> >> ADOdb date to work )
> >
> > This is not the correct thing to do, as you will lose timezone 
> > information. The W3C format only stores UTC offsets (in the form of
> > +00:00). However, that same UTC offset can be used in different 
> > +areas
> > with different DST changes. Best thing is to store in Unix
> timestamps.
> 

Timezones are a pain :)

> OK - I think I understand what is 'missing' now!
> 
> The only thing ever stored in the database *IS* Unix timestamps. Doing 
> anything other than that is unmanageable, yet some frameworks use 
> 'server based' times in their systems, simply because they do not 
> bother with daylight saving and only 'serve' one timezone!
> 

Not sure I understood this, especially "unmanageable". The important part is
to be consistent. 

Unix timestamps are useful because they in UTC. 
But there is nothing wrong with storing only ISO dates in a database. 

Consider these examples:

        // Datetime parsed as GMT
        date_default_timezone_set('GMT');
        $d = new Datetime('2008-06-05 00:00:00');
        echo $d->format('U e c'); // 1212624000 'GMT'

        // Timestamp parsed as GMT
        date_default_timezone_set('America/Montreal');
        $d = new Datetime('@1212624000');
        echo $d->format('U e c'); // 1212624000 'America/Montreal' <--
shouldn't this be UTC?

        // Datetime parsed as GMT
        date_default_timezone_set('America/Montreal');
        $d = new Datetime('2008-06-05 00:00:00', new DatetimeZone('GMT'));
        echo $d->format('U e c'); // 1212624000 'UTC' <-- not GMT?
        
        // Datetime parsed as 'America/Montreal'
        $d = new Datetime('2008-06-05 00:00:00', new
DatetimeZone('America/Montreal'));
        echo $d->format('U e c'); // 1212638400 'America/Montreal'

** can any php dev answer the <-- questions?

Personally, I prefer storing all dates in a database in a given timezone
(i.e. 'America/Montreal') 
It's convenient and easy to read. The big drawback is it needs to clearly
documented that all dates in the database are in this timezone and must be
converted when a) parsing user datetime b) displaying user datetime 

i.e.

// From user input to database 
$dbDate = new Custom_Datetime($_POST['userDate'], new
DatetimeZone($_POST['userTz']));
$dbDate->setTimeZone('America/Montreal'); // for storing to database

// From database to user
$userDate = new Custom_Datetime($dbDate, new
DatetimeZone('America/Montreal'));
$userDate->setTimeZone($userTz); // to display date in user's timezone

Unix timestamps are simpler since you know they are always in UTC.

Just thought I'd raise that there's nothing wrong with storing all dates as
ISO in a given timezone. It takes a little more work but if your consistent,
it can managed. 

If I'm wrong, please let me know :)

  



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to