Skip to content

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

@rob975

Description

@rob975

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):

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions