Re: Date methods simplified

From: Date: Tue, 21 May 2002 23:58:18 +0000
Subject: Re: Date methods simplified
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-6309@lists.php.net to get a copy of this message
I just realized this was in pear, it looks really nice (and would have saved me a bit of work yesterday if I'd seen it :) anyway - A few ideas another vote adding $date->utime (even if it didnt work for dates outside 70-38...) it will do when we all get 64 bit processors :) - and then I can $seconds =$totime->utime - $fromtime->utime; the setDate method uses scanf to read dates, and then sets the date directly with list($this->year,$this->mont......) = scanf('%4f-.... etc. since you have methods for setMonth(),setDay() etc. would it not be 'usefull'?? for setDate to call the setDay(etc.) methods to validate the data.. and return TRUE/FALSE hence setDay/Month/Date would return TRUE/FALSE if the date was valid or not..... anyway I'm off this morning to add require_once('Date.php') to a few files.... thanks, alan Baba Buehler wrote:
Nicolas Hoizey wrote:
Hi all, I'm looking at the Date package, and I wonder why addSeconds and substractSeconds are so big. I think addSeconds could be the following: function addSeconds($sec) {
    $this->setDate($this->getDate(DATE_FORMAT_UNIXTIME) + $sec, DATE_FORMAT_UNIXTIME);
}
This would make Date only valid for dates that are representable in UNIXTIME format, roughly 1970-2038... one of the design goals of Date was a representation that worked for dates outside of the UNIXTIME range. If you were only going to use the UNIXTIME format alone, you'd be better off with the built-in PHP functions. Time in seconds is only used where absolutely required (daylight savings time information) and for compatability with other code that uses the "time-in-seconds" format. As to shortening/optimizing any of the methods... I'm sure there is room for improvement. Date is my "first pass" and I only focused on functionality. If you've got ideas/patches for improvements, please post them or send them to me. baba


« previous php.pear.dev (#6309) next »