erlangbureau/jamdb_oracle

Wrong DateTime read from 'TIMESTAMP WITH TIMEZONE'

Opened this issue · 6 comments

Hi there,

I think the fix done here: #153 (comment)
wasn't quite right or complete.

When I have a value like "2024-02-07 13:00:00 +01:00" in the database, in a column of type "timestamp with timezone",
which means 12 o'clock in UTC, then I get a DateTime value like #DateTime<2024-02-07 12:00:00+01:00>} back.

Looking at the code in jamdb_oracle.ex, I assume decode get's called with tz='01:00', but with an hour value where the offset is already applied. Seems a bit weird - maybe that's coming from the Erlang code; I don't know. I cannot properly debug this right now.

The schema I use for that column is timestamps using the type :utc_datetime... so maybe the tz can be ignored in decode? Sounds wrong, too.
Maybe you can check and confirm this?

Thanks!

Now result in UTC plus TZ for information.

How to add/subtract hours and minutes to/from datetime in elixir ?

That would be

DateTime.add(dt, v, :minutes)

There is also the Timex library for more sophisticated things. I have also seen tz="Berlin/Europe" being passed in, if the value is generated by "sysdate" instead of "systimestamp" - but I don't need that currently.

commit
It works for simple tz like +01:00 +03:30 -01:00
For named tz datetime remains in UTC

Please try stage branch.
Now it works better.

Yes, looks better. Thank you!

fix Etc/GMT+- tz
Etc/GMT+1 => -01:00
Etc/GMT-1 => +01:00