FYI The parse(Date) method just calls Flex's built in parser and returns
null if the result's no good.
-J

On Sat, May 24, 2008 at 10:41 AM, Josh McDonald <[EMAIL PROTECTED]> wrote:

> YMMV :)
>
> //ISO date format - SOAP
>
> static public const ISO_DATE : RegExp =
> /^([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2}:[0-9]{2})(\.[0-9]+){0,1}(.*)$/
> ;
>
>
> //Parses ISO dates (from SOAP etc) - probably only works with valid ISO
> dates, innit.
>
> static public function parseIso(dateStr : String) : Date {
>
>  /* trace("parseIso(" + dateStr + ")"); */
>
>
>  if (dateStr == null) return null;
>
>
>  //Asplode input
>
>
>  var matches : Array = dateStr.match(ISO_DATE);
>
>  if(matches == null || matches.length < 5) {
>
> trace(dateStr + " is not a valid ISO date, buddy.");
>
> return null;
>
> }
>
>  var datePart : String = matches[1];
>
> var timePart : String = matches[2];
>
> var msPart : String = matches[3];
>
> var timeZone : String = matches[4];
>
>  /* trace("datePart = \"" + datePart + "\"");
>
> trace("timePart = \"" + timePart + "\"");
>
> trace("msPart = \"" + msPart + "\"");
>
> trace("timeZone = \"" + timeZone + "\""); */
>
>
>
> //Reassemble into a string flex's built-in parse can grok
>
>  var newString : String = datePart.replace("-","/").replace("-","/");
>
> newString += " ";
>
> newString += timePart;
>
> newString += " ";
>
> newString += "GMT" + timeZone.replace("Z","-00:00").replace(":","");
>
>  /* trace ("New string = " + newString); */
>
>  var d : Date = parse(newString);
>
>
>  /* trace("flex's parse of " + newString + " led to " + d + ", setting
> ms"); */
>
>  if (d != null)
>
> d.milliseconds = parseInt(timePart.substr(1,3));
>
>  /* trace("final parse of " + dateStr + " led to " + d); */
>
>  return d;
>
> }
>
> On Sat, May 24, 2008 at 12:26 AM, cesarerocchi <[EMAIL PROTECTED]>
> wrote:
>
>>   Hi,
>>
>> AFAIU there is no support to parsing ISO8601 dates in Flex.
>>
>> Does anybody have a clue or pointer to some library?
>>
>> Thanks,
>>
>> -c.
>>
>> --
>> http://spreadingfunkyness.com/posty
>>
>>  
>>
>
>
>
> --
> "Therefore, send not to know For whom the bell tolls. It tolls for thee."
>
> :: Josh 'G-Funk' McDonald
> :: 0437 221 380 :: [EMAIL PROTECTED]
>



-- 
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]

Reply via email to