I am trying to add my users timezone offset to my DB query, since the dates in my MongoDB database are saved in UTC by default. Basically, I'm trying to query by the users 'today'.
I have my users Timezone. For this example let's say it is 'America/New_York' which currently has a -04:00 offset.
In the backend I am making a query:
let presentHour = new Date().getHours(); //current hour of the day
let presentDay = new Date().getDate(); //current day of the month
let presentMonth = new Date().getMonth(); //current month of the year
let presentYear = new Date().getFullYear(); //current Year
Mood.find({
userId: req.user._id,
createdAt: {
"$gte": new Date(presentYear, presentMonth, presentDay, presentHour, 0, 0, 0),
"$lt": new Date(presentYear, presentMonth, presentDay+1, 23, 59, 59, 999)
} ....
As you can notice, I am not accounting for the offset.
From moment.js I am getting the timezone offset value like this:
-04:00
What is the best way to account for this in my query?