How to store date and time in Meteor for range queries?

My app needs to create objects that will have startDate shown in 3 different time zones in the browser. The date must also contain the exact time. The date should be stored in such a way that it allows you to query "give me everything for a date between X and Y" and parse it down to 3 time zones.

My question is what is the best way to store (and retrieve) the date and time so that I can query it later in date ranges, should I use moment.js? What I was thinking of is storing the date and time in both one unix timestamp in the database, and when reading it, it just parses it into the date and time with that particular timezone. Is this approach correct, or should I store it as a simple javascript Date? Can mongoDB query unix timestamps as date ranges, or is simple Date objects needed?

Thank.

+3


source to share


1 answer


Everything you need to know about it can be found here . Highlights:



  • Store dates as JavaScript Date

    objects. They have all the benefits of requesting whole timestamps, but you don't need to convert them back to objects Date

    to use them.

  • Range queries work as follows: Posts.find({creation_date: {$gte: startDate, $lt: endDate}})

  • You should either make the server inserts or use the timesync package to prevent clock skew problems.

  • You can use moment-timezone to format dates in different timezones. egmoment(date).tz("America/New_York").format('l LT')

+5


source







All Articles