While working on multiple timezones, I have a case where I create shifts in multiple timezones, now users apply for those shifts.
It’s highly time-sensitive. Now what I want to take input of which timezone the shift is in (example Australia/Sydney
)
Solution : Now while before saving it into the database I am converting the timezone to UTCoffset meaning in example Australia/Sydney
timezone I am setting offset with -
example Australia offset is 600 then -600 setting the offer and storing into the db.
const getUTCOffset = timezone => Intl.DateTimeFormat([], {timeZone: timezone, timeZoneName: 'shortOffset'}).formatToParts().find(o => o.type === 'timeZoneName').value.match(/-?d+/)[0]*60;
(getUTCOffset('Australia/Sydney'))
Is there anything I am missing here? What could be the optimal solution for this?