date time parsing
I worked on my human-readable date/time parsing library some more tonight and inched it ever closer to something I would feel comfortable showing others :)
I finally broke down and dug into some borrowed code that I was using to parse w3c dates and found the error in one of the regexes that I probably introduced while inserting it into my code - gotta love complex regex's !. I also worked on the core parsing code to add some scary if's to handle edge cases that were allowing items like "5 min" and "5 hours before noon" to parse but not allowing "next week" or "next tuesday" to parse. So now the following unit tests are handled:
True next week
False 2005-02-23
(2005, 2, 23, 0, 0, 0, 2, 54, 0)
(2005, 2, 22, 19, 0, 1, 1, 53, 0)
True 5 minutes from now
True 5 min from now
True 5m from now
True in 5 minutes
True 5 min
True 5 min before now
True 5 min before next week
True 5 hours from noon
True 5 hours before noon
True in 2 weeks
True 7 days before now
True next day
True tomorrow
True yesterday
True next week
True last week
False next wednesday
(2005, 11, 1, 23, 39, 13, 1, 305, 0)
(2005, 10, 31, 23, 39, 14, 0, 304, 0)
True next friday
True Inc(month=4) from Jan 1, 2004
True Inc(month=12) from Jan 1, 2004
True Inc(month=14) from Jan 1, 2004
The issue with "2005-02-23" seems to be a timezone problem - the borrowed w3c parsing code had gmtime assumptions and I may have not weeded out all of them (my code has localtime assumptions :) The "next wednesday" issue seems to be a off-by-one case as it only fails when the test is run on a Wednesday or Thursday, even though I am taking great pains in the test code to make sure all tests are relative to a known date to avoid this exact issue.
I gotta say, it's getting close -- next comes some basic localization refactoring and then I'll start running some comparisons for coverage and also performance against the Perl Time::Date library.