Parsing Strings to Dates in Flex 2 / ActionScript 3

Submitted by Falken on
Like most programmers, my users will enter as many funny formats for their dates as they can, given the chance in legacy systems with insufficient checks on user input.
But it's OK, says I, because in ActionScript version 3 (which means Flex 2 most of the time), the Date class will take a string as an argument, and turn it into a real Date.
Ahh. No. It won't. It'll make a half hearted attempt, and generally fail or make a total hash of it.

So, what to do ?
Write your own of course.
And here it is, with a few other functions I needed to make up for the lack of proper Date/Interval arithmetic functions.

What it doesn't do:
  1. Localisation. Mainly because I don't know a good way to detect if the user is in a locale that wants normal triplets (d/m/y) or backwards US style ones (m/d/y). Ideas welcomed.
  2. Non-English text. Mainly because I only really speak English, it will only work if you use English month names (or the first 3 letters there of) and day-of-month suffixes (th, rd). So '3rd December 2007' will parse OK, but '3rd Dicembre 2006' won't.
  3. Gregorian calendar only. I really don't want to have to think about other data systems right now :-)
Good luck with it, and I'd enjoy reading any comments you have.