I have two moments with timezone created using moment-timezone:
var moment = require('moment-timezone');
var startTime = moment.tz('2017-10-17 09:00', 'America/Los_angeles');
var endTime = moment.tz('2017-10-17 23:00', 'America/Los_angeles');
Note that the two moments are on the same day in America/Los_angeles timezone - one at 9 AM and another at 11 PM. However they may not be on the same day in the local timezone and certainly not in UTC. Is moment.isSame() timezone aware? Can I rely on the following expression to always return true:
startTime.isSame(endTime, 'day')
A followup question: I know that the moment object simply wraps the JavaScript Date object. Does the moment.tz() object remember the timezone as well?
Moment objects do indeed remember their time zone when constructed using a named time zone or converted to a named time zone.
The isSame function, when given an argument like 'day' will get the year, month, and day values from each object, and compare those numerically.
In other words, even if two moments in time wouldn't be in the same day when evaluated in UTC or in one time zone or the other, they could still have the same date in their own local representation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With