Micha Roon
Micha Roon

Reputation: 4007

different time zones on client and server

I am building a time tracker app that allows to create time entries for start and end times. The logic works fine, now my last problem is that the time entries are stored in GMT and the client is in GMT+1

What happens is that the time is stripped off one hour before it is stored in the database. This is fine. But then the hour is not added back when the time is displayed in the client.

My question is: how can I tell Meteor what time zone the client is in?

thank you for any hint

UPDATE I use the excellent datejs library to manipulate dates and times and it is fairly easy to add the UTCOffset for every time entry. I was wondering if it is possible to automate the process as Meteor did not ask me if it should store the times in GMT or another time zone.

UPDATE The dates in Meteor are passed to the client as strings. The string representation of the date is not parseable by Date.js but it can be used as parameter to the constructor. Therefore if you create the dates like so: var myDate = new Date(entity.dateField) it works but if you try it var myDate = Date.parse(entity.dateField) you will get only null

Upvotes: 4

Views: 1835

Answers (1)

Jordan Scales
Jordan Scales

Reputation: 2717

Store everything in GMT and allow the user (client) to select a timezone (Session['timezone']), and apply any transitions in the front-end. Your server should only be concerned with GMT.

Upvotes: 4

Related Questions