erlangbureau / jamdb_oracle

Oracle Database driver for Erlang
MIT License
103 stars 46 forks source link

Wrong DateTime read from 'TIMESTAMP WITH TIMEZONE' #173

Open dfrese opened 5 months ago

dfrese commented 5 months ago

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!

vstavskyi commented 5 months ago

Now result in UTC plus TZ for information.

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

dfrese commented 5 months ago

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.

vstavskyi commented 5 months ago

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

vstavskyi commented 5 months ago

Please try stage branch. Now it works better.

dfrese commented 5 months ago

Yes, looks better. Thank you!

vstavskyi commented 5 months ago

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