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

Fix reading time format #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions nzpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2162,9 +2162,14 @@ def Res_read_dbos_tuple(self, cursor, tupdesc):
workspace = int.from_bytes(fieldDataP[:fldlen],
byteorder='little', signed=True)
time_value = time2struct(workspace)
time_format = "{0:02d}:{1:02d}:{2:02d}"
value = time_format.format(time_value[0],
time_value[1], time_value[2])
if time_value[3]:
time_format = "{0:02d}:{1:02d}:{2:02d}.{3:06d}"
value = time_format.format(time_value[0], time_value[1],
time_value[2], time_value[3])
else:
time_format = "{0:02d}:{1:02d}:{2:02d}"
value = time_format.format(time_value[0], time_value[1],
time_value[2])
row.append(value)
self.log.debug("field=%d, datatype=TIME, "
"value=%s", cur_field + 1, value)
Expand Down Expand Up @@ -2888,17 +2893,17 @@ def j2date(jd):

def time2struct(time):
time_value = []
time = int(time / 1000000)
# NZ microsecs

hour = int(time / 3600)
time = time % 3600
minute = int(time / 60)
second = int(time % 60)
us = time % 1000000
time = int(time / 1000000) # NZ microsecs
second = time % 60
time = int(time / 60)
minute = time % 60
hour = int(time / 60)

time_value.append(hour)
time_value.append(minute)
time_value.append(second)
time_value.append(us)

return time_value

Expand Down
4 changes: 2 additions & 2 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def test_RemoteUnloadBasicCompressed(self):
self.performOperation("./setup_all_datatype")
self.cursor.execute("CREATE EXTERNAL TABLE "
"all_datatypes_retunload_ext "
"(a_srno integer, a_char5"
"(a_srno integer, a_char5 "
"char(5), a_char20 char(20) not NULL, "
"a_char1000 char(1000), "
"a_varchar1 varchar(1), a_varchar50 varchar(50), "
Expand Down Expand Up @@ -1270,7 +1270,7 @@ def test_FetchLatinUtf(self):
self.assertEqual('î·®ð£', c5, "ERROR: Data Difference")
self.assertEqual('ó´<9a><90>𣨰ð¥»<85>ô<8a>°¦ð¨<88>¾ó·¿<90>óµ'
'¿¡ô<85><8c>«ð<9d'
'><9b>»ô<8c>³<81>ê<8b>ªð <89>¨ô<8b><82><93>ô'
'><9b>»ô<8c>³<81>ê<8b>ªð <89>¨ô<8b><82><93>ô'
'<8c>½<9a>æ¢<8b>è°<9c>ô<', c6,
"ERROR: Data Difference")
self.assertEqual('å', c7, "ERROR: Data Difference")
Expand Down