rsanchez / json

Output ExpressionEngine data in JSON format.
http://devot-ee.com/add-ons/json/
101 stars 234 forks source link

entry_date timestamps are returned as string #9

Closed GDmac closed 12 years ago

GDmac commented 12 years ago

Rob, It took me some time to figure out why dates weren't being parsed by a javascript calendar. I followed the example from your readme new Date(data[i].entry_date), but, seems that (at least in Google-Chrome) doesn't work somehow if the timestamp in the json object is a string;

// timestamp as string
var data = { entry_date : "1325602858000" }

// returns NaN
var entryDate = new Date( data.entry_date );
entryDate.getTime() 

The long route is to return date type fields as integer (should an empty expiration_date be 0 ?) The quick solution is to typecast it in javascript

// works by typecasting to number
var entryDate = new Date( Number(data.entry_date) );
entryDate.getTime() 

What are your thoughts on this?

GDmac commented 12 years ago

And, already saw this is in the develop branch :-)

rsanchez commented 12 years ago

This is fixed in the develop branch 150175efacbfa968795327e410ebc8d405b7f81b. Haven't had time yet to make a release.