Gah! Dates must be simpler

VSarkiss on 2003-05-16T02:52:42

Dave Rolsky wrote an article a while back about how there are too many date-handling modules in CPAN. When I read it, I thought, "Absolutely, an overhaul is really needed."

Tonight I was reminded once again how bad the situation really is. There are too many modules, alternating between too much and too little. (Just "too", as in "too many notes!") What happened to "simple things should be simple, complicated things should be possible"?

I had six rows of dates, and all I wanted was, "Give me the next business day". After twenty minutes of floundering around with Date::Calc and Date::Calendar and their kin, I gave up, and just looked up each row in a real calendar: "Lessee, Memorial day is the 26th, so it's Tuesday."

I know someone will post a reply of "Just use Date::Foobar" or "In Date::Calc, just get the date in Tasmania and subtract the phase of the moon." You know what? By the time I got through the docs, wading through how to figure the Coptic calendar and the umpteen routines to calculate Easter, I was just too fed up to continue. Do the people that wrote this stuff really use it? Or did they just throw the kitchen sink in there because they could?

I hope the DateTime group makes things better, but frankly, glancing at the modules page makes me wonder if they're just adding fuel to the fire. "Baby Time"? "Pataphysical Calendar"? Yeah, those will be really useful.


Dealing with dates

dws on 2003-05-16T03:03:12

I'm coming to believe that one of the fastest ways of converting a string date to an integer is via table lookup. Look at the string just long enough to figure out which table (or hash, or whatever) to do the lookup from, then use the string as a key. A classic space-for-time trade-off. And with ~365.25 distinct dates per year, it's really not all that much space to deal with 20 years worth of days, even in multiple formats.

Core modules

koschei on 2003-05-16T03:40:21

Odds are, you won't ever need a DateTime::Calendar module.

Odds are, you won't ever need half the Format modules.

DateTime itself, DateTime::(Set|Span), and probably one or two of the format modules (probably Strptime or Builder since they're the most generic), are all most people will need. [Though Builder needs some refactoring since its simple cases have gotten a bit too complex.]

I don't think anyone's bothered to write business day stuff yet. Contributions are welcome, of course =) I think someone was working on representing holidays and such, which would be useful for such a module.

Join the list! =)

"next business day" is a hard problem

merlyn on 2003-05-16T09:48:34

Give me the next business day
Well, actually, you happen to pick one of the harder problems just then. You can state the problem easily, but then you have to answer a lot of questions:
  • What business?
  • What part of the world?
  • What exceptions?
So, while it seems easy at first, it's one of the more difficult issues.

Re:"next business day" is a hard problem

VSarkiss on 2003-05-16T14:29:53

Exactly, I realize it's nontrivial; that's why I went to find a module rather than roll my own. My point was that the interface and documentation were so complicated that the modules ended up not being of any help. As a contrasting example, CGI parameter parsing can be tricky, but CGI.pm packages up the difficulty for you, giving you a simple interface. That's not the case here.

Not too much

petdance on 2003-05-16T13:13:42

What we really need is a date/time handling module that is also a text templating system.

Re:Not too much

jplindstrom on 2003-05-16T22:08:53

...and can send e-mail :)

Re:Not too much

pne on 2003-05-21T06:37:24

...and can interface to a database ;)

Re:Not too much

chaoticset on 2003-05-21T15:08:27

Don't forget a graphics library!

Date::Manip

afresh1 on 2003-05-17T00:57:32

I have always just used Date::Manip it even has &Date_NextWorkDay.

Dunno if that helps, or complicates issues :-)

Re:Date::Manip

barbie on 2003-05-19T11:19:03

Except that its huge and written in pure Perl, thus can be slower than smaller modules or ones written in C.

However, as I have yet to find a working Win32 version of DateTime, Date::ICal does a pretty good job.