views:

206

answers:

4

Hi All

I'm looking into basic time functions (creating a UTC timestamp and converting into a local timezone). The first set of tutorials i encountered pointed toward PEAR as it's better at avoiding overspill errors in calculations. Now, mid-way through another, it appears that PEAR has issues with some of it's timezone functions running on certain OS's. The author inferrs that PHP5 is more stable! I'm now a bit confused as to the best. Can you reccommend from experince?

A: 

I've used PEAR's Date classes with no problems. It would be interesting to see the tutorial you're referring to. Is it on the web somewhere?

Joonas Pulakka
+1  A: 

I'm pretty happy with the PHP5 built-in DateTime class. It wraps the good old time functions in a-kind-of OO manner.

For a real Swiss Army knife, try Zend_Date. A lot of bells and whistles there. Up to sunrize/sunset data.

Ivan Krechetov
I support checking out Zend_Date. I use it and it really beats the native PHP or PEAR date handling by far!
tharkun
A: 

When working with timezones I generally set the timezone of the application and everything else is handled accordingly. Server is always GMT.

Check out putenv

Also you should be running PHP5 unless you have a legit reason to be using 4. 4 = crap.

Syntax
A: 

I've used both (though I used PHP5's more than Pear) and you probably won't find either to be a perfect fit for you. Either route you'll probably have to do a lot of checking and trapping for problems then decide yourself how to handle it. Do you round it, default it, tell the user there was a problem or handle it silently? I tend to just round to the nearest correct date... but my apps so far have not required exact precision where date/times are concerned. My point is- you'll probably not find an out of the box perfect fit- so choose the one you find easiest to work with, then extend/adjust for your own needs.

Sherri