Bug: Saving array of dates as an array of strings
Parse saves array of dates [new Date()] as an array of Strings.
In database:
- we've got:
["2016-02-04T09:23:40.280Z"] - Instead of:
[{"__type":"Date","iso":"2016-02-04T09:23:40.280Z"}]
// on server
user.set("dates", [new Date()])
user.save().then(function() {
return user.fetch()
}).then(function() {
var dates = user.get("dates")
console.log(dates[0] instanceof String) // true
})
@flovilmart just to be clear, old Parse saves dates like this: [{"__type":"Date","iso":"2016-02-04T09:23:40.280Z"}], while new parse-server saves them as strings.
This causes crashes, like here:
var date = user.get("dates")[0];
date.getTime(); // crash, date is string
So it's incompatible with old Parse and breaks the code.
I'm not sure if enhancement is a good label here.
@FilipZawada does it occur only on array of dates?
I just ran that unit test:
it('should save an array of dates', (done) => {
let object = new Parse.Object('Object');
let dates = [];
while(dates.length != 5) {
dates.push(new Date());
}
let objectId;
object.set('dates', dates);
object.save().then(()=> {
objectId = object.id;
let q = new Parse.Query('Object');
return q.get(objectId);
}).then((object) => {
console.log(object.toJSON());
console.log(object.get('dates')[0].getTime());
done();
})
})
And this is the response I got:
{ dates:
[ { __type: 'Date', iso: '2016-03-15T14:18:57.888Z' },
{ __type: 'Date', iso: '2016-03-15T14:18:57.888Z' },
{ __type: 'Date', iso: '2016-03-15T14:18:57.888Z' },
{ __type: 'Date', iso: '2016-03-15T14:18:57.888Z' },
{ __type: 'Date', iso: '2016-03-15T14:18:57.888Z' } ],
updatedAt: '2016-03-15T14:18:58.630Z',
createdAt: '2016-03-15T14:18:58.630Z',
objectId: 'iMr8iONkOo' }
1458051828816
The dates are properly stored as objects like in the old parse server. And I can properly access the date object.
Closing this as it seems like we have a test case that covers this, and it's working. @FilipZawada if you are still seeing this problem, please open a new issue that includes a complete failing test case.