I'm sure this has been asked before, but I've definitely looked and cannot find an answer. I'd appreciate a link if this has an obvious/known solution.
I'm dealing with a legacy database where datetimes are stored as separate dates and times. The underlying datatypes in Postgres are "date" and "time without time zone [21:45:00]". Dates are in YYYY-MM-DD format, while times are HH:MM:SS. All records are from the same location, so the only difference comes from daylight savings.
Given a date string (YYYY-MM-DD), time (HH:MM:SS), and a known location (eg. "Europe/Oslo"), how can I construct a valid Javascript Date object with the appropriate timezone information?
Example inputs:
[
{ date: '2022-06-21', time: '21:45:00', location: 'Europe/Oslo' },
{ date: '2022-12-21', time: '21:45:00', location: 'Europe/Oslo' }
]
Desired output (valid UTC string or Date object equivalent):
['2021-06-21T19:45:00Z',
'2021-12-21T20:45:00Z']