Re: [flexcoders] Date issue - need to create date out of string like xxxx-xx-xx from XML

2008-09-16 Thread Josh McDonald
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:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On
 Behalf Of *Tim Rowe
 *Sent:* Monday, September 15, 2008 10:56 PM
 *To:* flexcoders@yahoogroups.com
 *Subject:* RE: [flexcoders] Date issue - need to create date out of string
 like -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:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On
 Behalf Of *Josh McDonald
 *Sent:* Tuesday, 16 September 2008 3:43 PM
 *To:* flexcoders@yahoogroups.com
 *Subject:* Re: [flexcoders] Date issue - need to create date out of string
 like -xx-xx from XML

 Old code, probably terribly inefficient:

 //-MM-DD
 static public const SIMPLE_INTL_DATE : RegExp =
 /^(\d{4})[-\/](\d{2})[-\/](\d{2})$/;

 //-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]


Re: [flexcoders] Date issue - need to create date out of string like xxxx-xx-xx from XML

2008-09-16 Thread Josh McDonald
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:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On
 Behalf Of *Tim Rowe
 *Sent:* Monday, September 15, 2008 10:56 PM
 *To:* flexcoders@yahoogroups.com
 *Subject:* RE: [flexcoders] Date issue - need to create date out of
 string like -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:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On
 Behalf Of *Josh McDonald
 *Sent:* Tuesday, 16 September 2008 3:43 PM
 *To:* flexcoders@yahoogroups.com
 *Subject:* Re: [flexcoders] Date issue - need to create date out of
 string like -xx-xx from XML

 Old code, probably terribly inefficient:

 //-MM-DD
 static public const SIMPLE_INTL_DATE : RegExp =
 /^(\d{4})[-\/](\d{2})[-\/](\d{2})$/;

 //-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]


RE: [flexcoders] Date issue - need to create date out of string like xxxx-xx-xx from XML

2008-09-16 Thread Tim Rowe
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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Josh McDonald
Sent: Tuesday, 16 September 2008 3:43 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Date issue - need to create date out of string
like -xx-xx from XML



Old code, probably terribly inefficient:

//-MM-DD
static public const SIMPLE_INTL_DATE : RegExp =
/^(\d{4})[-\/](\d{2})[-\/](\d{2})$/;
   
//-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]
mailto:[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
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
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf
-1e62079f6847 
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo
http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo ! Groups
Links


   (Yahoo! ID required)

   mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED] 








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

http://flex.joshmcdonald.info/ http://flex.joshmcdonald.info/ 

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


 


RE: [flexcoders] Date issue - need to create date out of string like xxxx-xx-xx from XML

2008-09-16 Thread Alex Harui
Just out of curiosity, does Date.parse() suck that badly?  I would just regex 
replace - with / and hand it to Date.parse().

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tim Rowe
Sent: Monday, September 15, 2008 10:56 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Date issue - need to create date out of string like 
-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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Josh 
McDonald
Sent: Tuesday, 16 September 2008 3:43 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Date issue - need to create date out of string like 
-xx-xx from XML
Old code, probably terribly inefficient:

//-MM-DD
static public const SIMPLE_INTL_DATE : RegExp = 
/^(\d{4})[-\/](\d{2})[-\/](\d{2})$/;

//-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]mailto:[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]mailto:[EMAIL PROTECTED]



Re: [flexcoders] Date issue - need to create date out of string like xxxx-xx-xx from XML

2008-09-16 Thread Josh McDonald
Heh. Like I said, old and crap code :)

On Tue, Sep 16, 2008 at 3:56 PM, Tim Rowe [EMAIL PROTECTED] wrote:

  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:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On
 Behalf Of *Josh McDonald
 *Sent:* Tuesday, 16 September 2008 3:43 PM
 *To:* flexcoders@yahoogroups.com
 *Subject:* Re: [flexcoders] Date issue - need to create date out of string
 like -xx-xx from XML

   Old code, probably terribly inefficient:

 //-MM-DD
 static public const SIMPLE_INTL_DATE : RegExp =
 /^(\d{4})[-\/](\d{2})[-\/](\d{2})$/;

 //-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]


Re: [flexcoders] Date issue - need to create date out of string like xxxx-xx-xx from XML

2008-09-16 Thread Josh McDonald
Old code, probably terribly inefficient:

//-MM-DD
static public const SIMPLE_INTL_DATE : RegExp =
/^(\d{4})[-\/](\d{2})[-\/](\d{2})$/;

//-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]


RE: [flexcoders] Date issue - need to create date out of string like xxxx-xx-xx from XML

2008-09-16 Thread Peter Farland
Josh, have you logged bugs for specific issues with SOAP date unmarshalling?
Pete

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Josh 
McDonald
Sent: Tuesday, September 16, 2008 2:05 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Date issue - need to create date out of string like 
-xx-xx from XML

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


Re: [flexcoders] Date issue - need to create date out of string like xxxx-xx-xx from XML

2008-09-16 Thread Josh McDonald
Actually I haven't. I voted on one, that in order to fix would require some
actual safety checking be put into the date parsing (SDK-14932) - this is an
actual bug as it's failing to parse valid dates. I also voted on the general
let me validate responses bug (ASC-3153), as mostly my date problems stem
from Flex simply producing rubbish dates instead of a null or an exception
when encountering invalid XML data, which I assume was a design decision
(for speed's sake) rather than an actual bug. Some stricter unmarshalling
code that regexes against the ISO standards is still on my to-do list, but
it's not that near the top yet :)

-Josh

On Tue, Sep 16, 2008 at 11:24 PM, Peter Farland [EMAIL PROTECTED] wrote:

 Josh, have you logged bugs for specific issues with SOAP date
 unmarshalling?
 Pete

 From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
 Behalf Of Josh McDonald
 Sent: Tuesday, September 16, 2008 2:05 AM
 To: flexcoders@yahoogroups.com
 Subject: Re: [flexcoders] Date issue - need to create date out of string
 like -xx-xx from XML

 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

 

 --
 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]