I have 3 separate fields of types VARCHAR
(contains timezone, for example 'Europe/Rome'), DATE
and INTERVAL
. And I want to combine them in query so that I get TIMESTAMP WITH TIME ZONE
. The rule of making this value is:
Noon of specified date in given time zone, minus 12 hour and plus given interval (this -12 hours is needed to deal with DST).
Obviously adding/subtracting INTERVAL
is not a problem. My problem is that I don't understand how to create "Noon of specified date in given time zone".
A quick example:
- If I have timezone field 'Europe/Rome'
- Date is 2018-03-24 (Date of DST switch in this timezone)
- Interval is '1 hour'
The calculation should be like this:
- Create noon of specified date: 2018-03-24 12:00:00 at 'Europe/Rome' time zone
- Subtract
INTERVAL '12 hours'
, result is 2018-03-24 01:00:00 at 'Europe/Rome' time zone (because of DST) - Add
INTERVAL '1 hour'
, final result is 2018-03-24 02:00:00 at 'Europe/Rome' time zone.
How do I do point 1?
P.S. I cannot change schema of data. It comes from GTFS data that is loaded into postgres. In short, peculiarity of this schema is that it stores timezone, date and time intervals in 3 different tables: agency, calendar_dates and stop_times (well, timezone may be in other table, but that's not important for this question).