views:

283

answers:

2

I am getting the following error: TypeError: Error #1034: Type Coercion failed: cannot convert "2010-01-02 23:28:17 UTC" to Date.

I am using WebORB to transfer data between Rails and Flex. The data coming from Rails is of type: 'ActiveSupport::TimeWithZone'. I am trying to assign it to a Flex 'Date' data type.

What am I missing?

+1  A: 

From the documentation: http://www.adobe.com/livedocs/flex/3/langref/Date.html#Date()

If you pass a string to the Date class constructor, the date can be in a variety of formats, but must at least include the month, date, and year. For example, Feb 1 2005 is valid, but Feb 2005 is not. The following list indicates some of the valid formats:

Day Month Date Hours:Minutes:Seconds GMT Year (for instance, "Tue Feb 1 00:00:00 GMT-0800 2005", which matches toString())

I think in Rails, what you need to do is calling strftime to format the date output that's going to be sent to Flex

time_with_zone.strftime("%a %b %d %H:%M:%S %z %Y") # => "Sun Jan 03 20:58:16 +0700 2010"
Sikachu
A: 

Thanks for the help but, oddly, that wasn't it. Your help, Sikachu, did put me on the right track. I couldn't simply assign the returned result--I had to feed it into the constructor. So, instead of doing this, which didn't work:

var flexDate:Date = server_result.date;

I did this, which works:

var flexDate:Date = new Date(server_result.date);
NJ