Re: Date String Parsing
by Sidhekin (Priest) on Nov 27, 2007 at 16:57 UTC
|
Time::ParseDate at least is a date string parsing module (duh!), and it passes your items 1-3. Oh, and it was good enough for RT. :)
Whether you would consider it "robust" or "well documented" I cannot say. Item 5 is technically a pass, but if this ability is enough for your needs, I again wouldn't know. Still, as it is pure Perl, I suspect you'll find a way. :)
Might be worth looking into, if you haven't already.
print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!
| [reply] [d/l] |
|
|
Sidhekin,
Thank you! This does seem to fit all my criterion on the surface. I am not sure how well it will work in practice but it gives me something to work from. I am not sure how I missed this when I was looking at existing wheels.
| [reply] |
Re: Date String Parsing
by jdporter (Paladin) on Nov 27, 2007 at 16:30 UTC
|
it seems silly to use a module if I am having to still do corner cases by hand
IMHO, in this case, it doesn't seem so silly. Date parsing is a big ugly problem, and
Date::Manip does remarkably well, considering. And if you could turn your corner-case fixes into patches to the module, that would be even better.
|
A word spoken in Mind will reach its own level, in the objective world, by its own weight
|
| [reply] |
|
|
| [reply] |
Re: Date String Parsing (TFM)
by tye (Sage) on Nov 27, 2007 at 20:24 UTC
|
Did you not find the documentation for Date::Manip or did you just not read it?
- DateFormat
-
Different countries look at the date 12/10 as Dec 10 or Oct 12. In the United States, the first is most common, but this certainly doesn't hold true for other countries. Setting DateFormat to "US" forces the first behavior (Dec 10). Setting DateFormat to anything else forces the second behavior (Oct 12).
If you wanted a listing of all of the different formats that it supports, then you misunderstand how it works. It supports more formats than could be simply listed. If you have FUD, then test it. Or go to the secondary documentation source, the source code (I recommend both):
if (/^$D\s+$D(?:\s+$YY)?$/) {
# MM DD YY (DD MM YY non-US)
($m,$d,$y)=($1,$2,$3);
($m,$d)=($d,$m) if ($type ne "US");
last PARSE;
So 01/02/03 defaults to MM/DD/YY but can be set to be DD/MM/YY. It doesn't support YY/MM/DD for that case, just YYYY/MM/DD, as is reasonable, IMHO.
| [reply] [d/l] |
|
|
tye,
Did you not find the documentation for Date::Manip or did you just not read it?
Since I quoted from it in my post, let's assume I found it and read parts of it. I have, at one point or another, read all of the documentation. I am guilty of not spending a lot of time with the source code.
It seems like my real crime is laziness. I am not interested in seeing a list of all the formats it supports. I am interested in a list of ambigous formats and settings to modify to specify which one to use. I want to be able to look at a table and that says if your string looks like this the module will see at as X. If you want Y then change this setting to Z. This is apparently a pipe dream.
| [reply] |
Re: Date String Parsing
by graff (Chancellor) on Nov 27, 2007 at 19:54 UTC
|
You said:
The sparse documentation doesn't ... [explain] what it would do in the circumstance of '02/01/03'.
In the absence of more information about your intended usage, I wouldn't know what sort of advice to give. Are you processing text that has been collected "from the wild" and trying to identify/normalize all date references? (Very hard target with no complete solution -- some errors are inevitable.) Are you soliciting date strings from users via some sort of form submission and hoping to normalize their inputs? (Easily solved with appropriate design of the form.) Something else?
If a string like "02/03/04" is coming from who-knows-where, it is intrinsically ambiguous -- one can only hope that there is enough contextual information in the data surrounding it to allow a human to interpret it correctly (it might not even be a date). Asking for a perl script to get it right might be expecting too much. | [reply] |
|
|
| [reply] |
Re: Date String Parsing
by perlfan (Parson) on Nov 28, 2007 at 04:28 UTC
|
When you mentioned pure Perl, I thought of Date::Pcalc. I am not sure how well it suites some of the other needs, but I've used it before to get date diffs, etc. | [reply] |
Re: Date String Parsing
by dragonchild (Archbishop) on Nov 27, 2007 at 16:34 UTC
|
Your requirement of "no laundry list" is a ridiculous requirement and should be dropped, thus allowing DateTime as the proper solution.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] |
|
|
| [reply] |
|
|
| [reply] |