Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TIMESTAMP WITH TIME ZONE storing offset from UTC (not named TZ) #373

Open
rob975 opened this issue Aug 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@rob975
Copy link

rob975 commented Aug 4, 2024

Currently naive datetime(s) are returned when column type is TIMESTAMP WITH TIME ZONE.
Issue #274 can be split into two tasks, one is supporting named time zones as per issue #20. The other task is supporting timestamps having only the offset from UTC.
I have no knowledge of Cython so I cannot create a PR but what I would try is:

--- a/src/oracledb/impl/base/buffer.pyx
+++ b/src/oracledb/impl/base/buffer.pyx
@@ -354,7 +354,10 @@ cdef class Buffer:
             tz_minute = ptr[12] - TZ_MINUTE_OFFSET
             if tz_hour != 0 or tz_minute != 0:
                 seconds = tz_hour * 3600 + tz_minute * 60
-                value += cydatetime.timedelta_new(0, seconds, 0)
+                tz_delta = cydatetime.timedelta_new(0, seconds, 0)
+                tz_utc = cydatetime.get_utc()
+                tz = cydatetime.timezone_new(tz_delta)
+                return value.replace(tzinfo=tz_utc).astimezone(tz)
         return value

     cdef object parse_interval_ds(self, const uint8_t* ptr):
@rob975 rob975 added the enhancement New feature or request label Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant