[TYPO3-dev] new DateTime-Object

Jochen Rau j.rau at web.de
Thu Mar 27 12:12:31 CET 2008


Hi Steffen,

I few weeks ago I changed the whole date handling of the extension 
"reservations" to the DateTime object. Actually it solves a lot of 
problems with timezones and supports an "object oriented way" dealing 
with dates.

But it has also a lot of pitfalls and is not very comfortable to use. 
Most of these issues are discussed in the article you mentioned:

> found a useful article about that too:
> http://laughingmeme.org/2007/02/27/

Some hints:
1. The method date_default_timezone_set('UTC') should be avoided, 
because it sets the default timezone for the rest of the script and 
therefore influences other extensions. (A solution can be to encapsulate 
  your script and restore the timezone settings.)
2. It's not as easy as it should be to transform from unix-timestamps to 
a DateTime object. A possible solution can be found in the source of 
"reservations" (setting time to midnight):
$dateObject = new DateTime(date('Y-m-d',$timestamp), new 
DateTimeZone('UTC'));
3. There is no handy way to say "set time to 00:00:00" without creating 
a new Object.

Despite these handicaps, the DateTime object is a big progress in 
dealing with dates.

Greetings
Jochen




More information about the TYPO3-dev mailing list