oracle / oracle/python-oracledb

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

Open
#373 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
451
Forks
119
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/oracledb/impl/base/buffer.pyx, at Buffer's timestamp parsing logic around the shown timezone-offset handling. Check how TIMESTAMP WITH TIME ZONE values are converted, then verify that offset-only values produce timezone-aware datetimes with the stored UTC offset rather than naive datetimes or named time zones.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.