Re: Date-class

From: Date: Thu, 19 Jul 2001 00:20:33 +0000
Subject: Re: Date-class
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-875@lists.php.net to get a copy of this message
Erik Hjortsberg wrote: > > Ok, I've written a date class for making atomic date instances. > The current Date classes do only provide static methods. > There is however a need for a common format for handling dates in an > application, especially in a multi-developer situation (such as PEAR). > > Anyhow, a short introduction > > * Instances are created by using the static Date::From* functions: > * > * $date = & Date::FromISO('2001-01-20 10:01:02'); > * $date = & Date::FromISO('2001-01-20'); > * $date = & Date::FromDatetime('20010120100102'); > * $date = & Date::FromTimestamp(979981262); > * > * To get output from the object use the as*() functions > * > * $date->asISO() => '2001-01-20 10:01:02' > * $date->asDate() => '2001-01-20' > * $date->asTime() => '10:01:02' > * $date->asDatetime() => 20010120100102 > * $date->asShortDate() => '20/01 > * $date->asDayInWeek() => 6 > * $date->asWeekNumber() => 03 > * $date->asTextualDay() => saturday (depending on your locale setting) > * > * You can also get and set more specific values > * > * $date->year() > * $date->month() > * $date->day() > * $date->hours() > * $date->minutes() > * $date->seconds() > * > * Supply a parameter to set the value > * > * $date->year(2002) > * $date->month(11) > * > * To compare two dates use > * > * $res = $date1->compareTo($date2); > > I've chosen to use a timestamp as internal representation for now. That > will probably change. > I've also tried to keep the extra methods to a minium to keep it simple. If > you want a special formatting you can do it with date('fsdafd', > $date->timestamp()). Plus, the methods provided by Date_Date are also helpful. Handy. How do you deal with timezones? To comply more with other classes, the "asXxx" methods should be renamed to "toXxx" (we havre toString in a bunch of places, inspired by Java) The date comparison function should return -1/0/1 so it cab be used with sorting. - Stig

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