Gents,
Odd issue with date. On client, after doing some stuff and getting user info:
let conversation = {
// other fields...
content: [],
};
// do random parsing... then
if (text != null) {
conversation.content.push({
date: new Date(),
text: text,
});
}
userUserCommInsert.call(conversation);
On server:
export const userUserCommInsert = new ValidatedMethod({
name: 'user.userComm.insert',
validate: new SimpleSchema({
// ... other validations
content: { type: Array },
'content.$': { type: Object },
'content.$.date' : { type: Date },
'content.$.text' : { type: Object, blackbox: true },
}).validator(),
run({ <whatever>, content }) {
if (Meteor.isServer) {
console.log(content);
}
},
});
Here is what is odd:
- If on client, i set
date: new Date().toUTCString();
, this falls foul with the validation:validated-method.js:75 Uncaught Error: Date must be a Date [validation-error]
. No hassles, I can work around that… - So now, I set
date: new Date()
on the client side. This passes validation no issues. So the actual date value is some large number of Unix milliseconds. But now, looking at theconsole.log(content)
on the server, shows up as:I20160810-13:14:19.550(10)? [ { date: Wed Aug 10 2016 13:14:19 GMT+1000 (AEST), I20160810-13:14:19.551(10)? text: { entityMap: {}, blocks: [Object] } } ]
How is this possible? Where is the conversion from Unix style milliseconds -> human readable happening. The plan is to move this to moment.js at some point, but ValidatedMethod is being odd here.
Thanks so much.
Tat