Parsing fancy for the New Year
Posted: Fri Jan 01, 2010 9:45 am
By way of wishing you all a Happy New Year, here's a date-related 'amusement/challenge' for you.
Visit the Lambdalator and find a date/time format that breaks my flimsy coding!
The handler function is parse-time, and it's like newLISP's parse-date, except that it tries to guess the format you've used, so you don't supply a format string. Here are some examples to get you started:
(parse-time "4:15")
; → Fri Jan 1 04:15:00 2010
(parse-time "1999-12-31T21:59:59-8:00")
; → Fri Dec 31 21:59:59 1999
(parse-time "1995-02")
;→ Wed Feb 1 09:41:43 1995
On NearlyFreeSpeech hosting it works in English only - switching to alternate locales doesn't work, apparently...
(What happened was, I started doing this as part of my Timeutilities FOOP module, but I soon realised trying to anticipate most date/time formats was going to be too much of a chore. I've sort of abandoned the project - haven't even started doing time zones... :))
For Hackers: the context is called ParseTime.
Visit the Lambdalator and find a date/time format that breaks my flimsy coding!
The handler function is parse-time, and it's like newLISP's parse-date, except that it tries to guess the format you've used, so you don't supply a format string. Here are some examples to get you started:
(parse-time "4:15")
; → Fri Jan 1 04:15:00 2010
(parse-time "1999-12-31T21:59:59-8:00")
; → Fri Dec 31 21:59:59 1999
(parse-time "1995-02")
;→ Wed Feb 1 09:41:43 1995
On NearlyFreeSpeech hosting it works in English only - switching to alternate locales doesn't work, apparently...
(What happened was, I started doing this as part of my Timeutilities FOOP module, but I soon realised trying to anticipate most date/time formats was going to be too much of a chore. I've sort of abandoned the project - haven't even started doing time zones... :))
For Hackers: the context is called ParseTime.