In Postgres I store data given to me by a user with:
Column | Type | Collation | Nullable | Default
------------+--------------------------+-----------+----------+---------
id | uuid | | not null |
value | numeric | | |
date | timestamp with time zone | | |
Now I'm presented with the requirement of maintaining the original timezone in which the data was produced. The timestamp with timezone
is normalized to the database's timezone and the original timezone is lost, so I must manually restore date
back from the normalized timezone before serving it back to the user.
Most solutions suggest adding an extra column to the table and storing the original timezone information together with the timestamp:
Column | Type | Collation | Nullable | Default
------------+--------------------------+-----------+----------+---------
id | uuid | | not null |
value | numeric | | |
date | timestamp with time zone | | |
tz | text | | |
So given that I'm using Go, which information should I extract from time.Time
to store in tz
for the most precise and seamless restoration?
date.Location().String()
doesn't seem right as it might return the value Local
which is relative.
And how should I restore the information from tz
back into to time.Time
?
Is the result of time.LoadLocation(tz)
good enough?