0

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?

flimflam57
  • 1,334
  • 4
  • 16
  • 31
  • I could try and compensate for the timezone by saving it as: new Date("2018-10-05T-07:00:00-04:00"), but when we are in standard time, it'll be the wrong offset. – flimflam57 Oct 01 '18 at 23:35
  • Is there a setting on compose where you configure the server's timezones? If timezones become a thing you may consider packages like `moment` that may ease this procedure. – Jankapunkt Oct 02 '18 at 06:46
  • Are both of the inserts happening from a meteor app, or is the compose.io happening from the compose dashboard? – Kelly Copley Oct 10 '18 at 01:00
  • @Kelly - Both inserts are coming from Meteor. – flimflam57 Oct 10 '18 at 14:38

1 Answers1

0

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.

flimflam57
  • 1,334
  • 4
  • 16
  • 31