Date/time sync logic

Hi Everyone!

I am trying to make an appointment/booking application on Meteor and am facing some date/time issues. I am thinking of writing that logic from scratch and need help from you lovely people :wink:

Q1) How do i make sure all Date/times are in UTC ?
Q2) I have made some time slots a user can select from (like below):

  • 9:00 - 9:59
  • 10:00 - 10:59
    etc etc
    These slots are selected on user end and the time i get is based on his browser/computer, how do i make all these sync together?
    In addition i have to make sure a user doesnā€™t book an appointment in the same slot which is already booked by another client.

I would really appreciate any pointers.

I was trying to do the same and eventually decided to use strings instead of dates. So store a date like "2016-05-02" or "2016-05-02 14:20" then use moment on both the client and the server to convert this to a date object (moment(stringDate, 'YYYY-MM-DD').toDate()). If you want to pass dates between the client and the server, just convert them to string locally with moment (moment().format('YYYY-MM-DD')) before passing them. This way nothing can go wrong :slight_smile:

Thanks Csiszi!

I understand your concept but how to sync the two (front-end and server-end) dates in the same timezone?
The new Date function on browser returns the userā€™s computer date which might be very different from serverā€™s date. However all the calculations need to cater for these differences.

https://themeteorchef.com/snippets/handling-timezones/ - This might be helpful for you. Not 100% sure though :frowning:

In my case the timezone was connected to an apartment which means the timezone was irrelevant (11:20 was always meant 11:20 ā€œapartment timeā€). If you have to deal with different timezones (e.g. you have to show 11:20 for person A and 9:20 for person B) than this approach wonā€™t work and you have to use Dates, but new Date() will always return local time with time-zone information in it.

Q1 ) use moment.utc()
if you need to display hours in local timezone use moment timezone

Q2) why do you need to get a time for fixed slots, hardcode slots and just remove unavailable slots based on bookings ?