scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

Allow Date type fields to be populated with date string (beside number or Date instance) #46

Closed royaltm closed 8 years ago

royaltm commented 8 years ago

It would be very nice if camo validator would accept field with declared type Data values as strings. Currently we may use numbers or date instances but no date strings.

I think simple Date.parse would suffice to interpret strings.

Why:

I'm using camo (with my neat hack) in a browser (via my own REST client for camo) and after serializing/deserializing JSON objects, all Date fields become ISO date strings on the backend.

The workaround is to: Date.prototype.toJSON = Date.prototype.getTime in the browser.

but I would like to leave Date.prototype.toJSON untouched and allow the camo validators to convert those date strings to Date objects.

scottwrobinson commented 8 years ago

Adding this to the todo list.

Thanks!

royaltm commented 8 years ago

Thanks!