FWIW, I do actually hand-off to Date.parse() as the last step in my hand-rolled XSD:DateTime parser :)
-Josh On Tue, Sep 16, 2008 at 4:05 PM, Josh McDonald <[EMAIL PROTECTED]> wrote: > I don't actually use that code I posted above, as all our dates come in via > SOAP, for which Flex's unmarshaller is even worse :) > > I like the strict checking you can do with a regex. Dates are an awful > touchy subject in this business. > > -Josh > > > On Tue, Sep 16, 2008 at 4:00 PM, Alex Harui <[EMAIL PROTECTED]> wrote: > >> Just out of curiosity, does Date.parse() suck that badly? I would just >> regex replace "-" with "/" and hand it to Date.parse(). >> >> >> >> *From:* [email protected] [mailto:[EMAIL PROTECTED] *On >> Behalf Of *Tim Rowe >> *Sent:* Monday, September 15, 2008 10:56 PM >> *To:* [email protected] >> *Subject:* RE: [flexcoders] Date issue - need to create date out of >> string like xxxx-xx-xx from XML >> >> >> >> It's got to just be total coincidence that what's virtually the same >> question has come up twice in the same day. >> >> >> >> The answer I provided earlier will also work, and will do so in ~5 lines >> of code. >> >> >> >> --Tim >> >> >> ------------------------------ >> >> *From:* [email protected] [mailto:[EMAIL PROTECTED] *On >> Behalf Of *Josh McDonald >> *Sent:* Tuesday, 16 September 2008 3:43 PM >> *To:* [email protected] >> *Subject:* Re: [flexcoders] Date issue - need to create date out of >> string like xxxx-xx-xx from XML >> >> Old code, probably terribly inefficient: >> >> //YYYY-MM-DD >> static public const SIMPLE_INTL_DATE : RegExp = >> /^(\d{4})[-\/](\d{2})[-\/](\d{2})$/; >> >> //YYYY-MM-DD - midday! >> static public function parseSimpleIntlDate(input : String) : Date >> { >> >> var parts : Array = input.match(SIMPLE_INTL_DATE); >> >> var d : Date = new Date(); >> d.milliseconds = 0; >> d.seconds = 0; >> d.minutes = 0; >> d.hours = 12; >> d.date = Convert.stringToInt(parts[3]); >> d.month = Convert.stringToInt(parts[2]) - 1; >> d.fullYear = Convert.stringToInt(parts[1]); //Not really >> necessary, since we're unlikely to have a year < 999, but you get that. >> return d; >> } >> >> public class Convert { >> >> private static const validButIgnoredCharactersInNumbers : RegExp = >> /[,\$]/g; >> >> public static function stringToInt(input : String) : Number { >> >> return parseInt(cleanupNumberInput(input)); >> } >> >> public static function stringToFloat(input : String) : Number { >> >> return parseFloat(cleanupNumberInput(input)); >> } >> >> public static function cleanupNumberInput(input : String) : String >> { >> >> if (input == null) return null; >> >> //Strip any initial 0s - don't wanna parse as octal, do we? >> var output : String = input; >> while (output.charAt(0) == "0" && output.length > 1) >> output = output.substr(1); >> >> return output.replace(validButIgnoredCharactersInNumbers, ""); >> } >> >> } >> >> On Tue, Sep 16, 2008 at 3:32 PM, Andrew Jones <[EMAIL PROTECTED]> wrote: >> >> Hello - >> I am having an issue creating a valid Flex Date object from a value >> returned to my app in XML. The returned value is 2008-09-14 (year- >> month-day), and no matter how I try, I can't create a valid date >> object from this. >> >> Has anyone ever had to do something similar, or have any ideas on what >> I might do? >> >> Andrew >> >> >> ------------------------------------ >> >> -- >> Flexcoders Mailing List >> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt >> Alternative FAQ location: >> https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 >> Search Archives: >> http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups >> Links >> >> >> >> >> >> >> -- >> "Therefore, send not to know For whom the bell tolls. It tolls for thee." >> >> http://flex.joshmcdonald.info/ >> >> :: Josh 'G-Funk' McDonald >> :: 0437 221 380 :: [EMAIL PROTECTED] >> >> >> > > > > -- > "Therefore, send not to know For whom the bell tolls. It tolls for thee." > > http://flex.joshmcdonald.info/ > > :: Josh 'G-Funk' McDonald > :: 0437 221 380 :: [EMAIL PROTECTED] > -- "Therefore, send not to know For whom the bell tolls. It tolls for thee." http://flex.joshmcdonald.info/ :: Josh 'G-Funk' McDonald :: 0437 221 380 :: [EMAIL PROTECTED]

