Re: Need for Date-object

From: Date: Thu, 19 Jul 2001 02:24:36 +0000
Subject: Re: Need for Date-object
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-876@lists.php.net to get a copy of this message
azatoth@hem.passagen.se (Erik Hjortsberg) wrote in news:5.0.2.1.0.20010717144147.00abb1b0@pop.student.lu.se: > I always find it a hassle to use date and time data in my php > applications. One have to convert and parse between mktime() and date() > and have to keep track of different parameters and different formats. > This is due to php absent handling of atomic dates, ie. objects. > Treating them as strings is not very efficient code-wise. > I've used some date-classes I've done myself, but it is clear that all > would benefit from a standardized way of handling dates. And I think if > would fit perfectly into what PEAR is about if we could provide a solid > date-class. > Now, I know that there's already a Date_Date class, but that consists > solely of static functions and cannot be used to provide atomic > date-objects. Furthermore, this is something that's already been > tackled by all major object-capable languages. So there's no need to > reinvent the wheel. So I ask all of you, given experiences from other > languages, what interface and functions would you wan't to see in a > common date-object? Yes yes, please! I crave a solid, well-written, (perhaps extensible thru inheritance) DateTime object. The capabilities of the object should be: - flexible internal reprsentation (i.e. no unix timestamp inside, ugh, but separate year, day, month, etc fields) - difference calculation of dates and times - addition and subtraction of months, weeks, etc - initialization from most commonly used datetime representations - flexible output functions (something like strftime) Basically, say I read a MySQL date field. Date object should be have a $year, $month, $day constructor, and perhaps a MySQLDate extension could directly handle MySQL date format.. so assuming I initialize the object with that date field, I want to be able to add 30 days to it, pass it on to my template object, and my template must be able to easily compare the Date to today's date, see whether the Date is a week old, see whether the Date is later than some other Date, compute the difference between them, subtract that difference from yet another Date object, put it back into the Date object itself and my framework will update the database with the Date object returned from the template :) Right now, I end up passing in a unix timestamp around which really irks me (what if the user specifies a date in the 1960's? not likely to happen with my app, but later on).... Sorry if I don't sound clear, too late for me today... - Oleg

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