I'm trying to wrap my head around Postgresql timezones, and I can't seem to figure this out. EST is "Eastern Standard Time" in America, and is typically UTC-5.
Example 1: Base Test
select '08/31/2011 12:00 pm EST'::timestamptz at time zone 'EST';
timezone
---------------------
2011-08-31 12:00:00
Example 2: Offset is +5
select '08/31/2011 12:00 pm EST' at time zone '+5';
timezone
---------------------
2011-08-31 12:00:00
Example 3: Offset is -5
select '08/31/2011 12:00 pm EST' at time zone '-5';
timezone
---------------------
2011-08-31 22:00:00
Clearly, everything is backwards. EST is again... supposed to be UTC-5. Now, I did search through documentation, and it does explain that things are "POSIX", which is backwards. (Positive offset is west of GMT, while negative offsets are east of GMT).
However, how do I get around this? At the application layer, I can always invert the + sign to a - sign, but that seems a bit messy to me IMO. Thus, my ultimate question.
At the database layer (Postgres), is there a way to use the "At Time Zone" syntax so that GMT-5 corresponds to EST? Or do I just have to invert everything at the application layer?
Use interval datatype as written in documentation to get proper behaviour:
Base test:
Timezone info:
Proper offset -5:
Proper offset +5: