Search code examples
cpostgresqldatetimesqldatatypes

Storing timestamp with timezone in Postgres DB with a C extension?


To put it short, on input to my Postgres DB I have a timestamp in format "2014-12-10T12:00:14+07:00", and I would like to use 'timestampandtz' Postgres C extension (https://github.com/mweber26/timestampandtz), but I don't know how to approach the question of determining the time zone.

Since the extension compares the input with the full timezone names in zones.c, the datatype won't know what to do with "+07:00" instead of "@ Continent/City", which it expects on the input.

The thing is, I need to pull out the city somehow from "+07:00", cause I do need Daylight Savings Time resolution. Also, I know that these timestamps are from only one country, so maybe determining the "@ Continent/City" can be thought out based on this.

Any POV on how to approach this challenge would be greatly appreciated, thanks!


Solution

  • I'm afraid that you are out of luck. There is no way to convert a time offset like +07:00 to a time zone like US/Eastern automatically.

    The reason is that the same time offset can belong to different time zones. For example, -05:00 currently could be America/Lima or US/Central, but these are different time zones – the former has no daylight savings time.

    So you will have to come up with a translation yourself, e.g. if you know what time zone all your data with a certain time offset belong to.