Saving dates in Mongo via Compose.io vs. dates in Mongo via Meteor

81 views Asked by At

In Meteor:

Events.insert({ 'start': new Date(2018, 9, 5, 7, 0, 0, 0) });

In Meteor Mongo the saved date:

{ 
  "start" : ISODate("2018-10-05T11:00:00.000+0000"), // UTC time
}

Browser will display date as 7AM, as expected (EDT).

HOWEVER, In Compose.io, the same Mongo insert will save the date:

{ 
  "start" : ISODate("2018-10-05T07:00:00.000+0000"), // UTC time
}

Browser will display date as 3AM.

Meteor's Mongodb seems to be doing the correct thing by compensating for my EDT and adding 4 hours. Compose inserts the date as is.

What's the best way to compensate without hard coding a value?

1

There are 1 answers

0
flimflam57 On

My solution was to use an ISO 8601 string without any UTC offset, instead of new Date().

Events.insert({ 'start': '2018-10-5T05:00:00);

This way Mongo won't store it as an ISO Date, but rather just a string that will be read by the browser as the exact date that was entered by the user. The browser won't offset the timezone, and it's just inserted as a string as is.