Date values set from the client side are persisted as strings #42

Open
lackac opened this Issue Sep 20, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@lackac

lackac commented Sep 20, 2012

I have noticed this with the MongoDB backend, but I suspect this applies to other adapters as well.

Steps to reproduce:

  1. create a route which sets a date on some field: model.set("users.42.updated_at", new Date())
  2. access this route directly from the server
  3. look at the data persisted in the database, it should be something like this: "updated_at" : ISODate("2012-09-20T11:57:07.637Z")
  4. now access this from the client side (e.g. with a link pointing to '/')
  5. look at the data persisted in the database, it should be something like this: "updated_at" : "2012-09-20T11:57:03.243Z"

I suspect this is a side effect of how JSON.stringify and JSON.parse handles Date objects.

@lefnire

This comment has been minimized.

Show comment Hide comment
@lefnire

lefnire Jan 13, 2013

hear hear, it's a rather pain. has anyone figured out how to run mongo queries on these stringified dates as a result? eg, db.users.find({ 'auth.timestamps.created_on' : {$lt : new Date()} }) doesn't work because dates are strings.

lefnire commented Jan 13, 2013

hear hear, it's a rather pain. has anyone figured out how to run mongo queries on these stringified dates as a result? eg, db.users.find({ 'auth.timestamps.created_on' : {$lt : new Date()} }) doesn't work because dates are strings.

@lefnire lefnire referenced this issue in HabitRPG/habitica Jan 25, 2013

Closed

Preen user document periodically #220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment