jamdb_oracle icon indicating copy to clipboard operation
jamdb_oracle copied to clipboard

Wrong DateTime read from 'TIMESTAMP WITH TIMEZONE'

Open dfrese opened this issue 1 year ago • 6 comments

Hi there,

I think the fix done here: https://github.com/erlangbureau/jamdb_oracle/issues/153#issuecomment-1763362647 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!

dfrese avatar Feb 07 '24 15:02 dfrese

Now result in UTC plus TZ for information.

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

vstavskyi avatar Feb 07 '24 16:02 vstavskyi

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.

dfrese avatar Feb 08 '24 16:02 dfrese

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

vstavskyi avatar Feb 08 '24 17:02 vstavskyi

Please try stage branch. Now it works better.

vstavskyi avatar Feb 09 '24 10:02 vstavskyi

Yes, looks better. Thank you!

dfrese avatar Feb 09 '24 16:02 dfrese

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

vstavskyi avatar Feb 10 '24 16:02 vstavskyi