Skip to content

Commit

Permalink
PHOENIX-4664 Time Python driver tests failing
Browse files Browse the repository at this point in the history
  • Loading branch information
stoty committed Mar 6, 2023
1 parent 76dc256 commit c32a62f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 2 additions & 5 deletions python-phoenixdb/phoenixdb/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def test_boolean(self):
self.assertEqual(cursor.description[1].type_code, phoenixdb.BOOLEAN)
self.assertEqual(cursor.fetchall(), [[1, True], [2, False], [3, None], [4, True], [5, False], [6, None]])

@unittest.skip("https://issues.apache.org/jira/browse/PHOENIX-4664")
def test_time(self):
self.createTable("phoenixdb_test_tbl1", "CREATE TABLE {table} (id integer primary key, val time)")
with self.conn.cursor() as cursor:
Expand Down Expand Up @@ -172,7 +171,6 @@ def test_time_full(self):
[2, datetime.datetime(2015, 7, 12, 13, 1, 2, 123000)],
])

@unittest.skip("https://issues.apache.org/jira/browse/PHOENIX-4664")
def test_date(self):
self.createTable("phoenixdb_test_tbl1", "CREATE TABLE {table} (id integer primary key, val date)")
with self.conn.cursor() as cursor:
Expand All @@ -194,8 +192,8 @@ def test_date_full(self):
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (2, ?)", [datetime.datetime(2015, 7, 12, 13, 1, 2, 123000)])
cursor.execute("SELECT id, val FROM phoenixdb_test_tbl1 ORDER BY id")
self.assertEqual(cursor.fetchall(), [
[1, datetime.datetime(2015, 7, 12, 13, 1, 2, 123000)],
[2, datetime.datetime(2015, 7, 12, 13, 1, 2, 123000)],
[1, datetime.datetime(2015, 7, 12)],
[2, datetime.datetime(2015, 7, 12)],
])

def test_date_null(self):
Expand All @@ -209,7 +207,6 @@ def test_date_null(self):
[2, None],
])

@unittest.skip("https://issues.apache.org/jira/browse/PHOENIX-4664")
def test_timestamp(self):
self.createTable("phoenixdb_test_tbl1", "CREATE TABLE {table} (id integer primary key, val timestamp)")
with self.conn.cursor() as cursor:
Expand Down
5 changes: 2 additions & 3 deletions python-phoenixdb/phoenixdb/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ def date_to_java_sql_date(d):


def datetime_from_java_sql_timestamp(n):
return datetime.datetime(1970, 1, 1) + datetime.timedelta(milliseconds=n)
return datetime.datetime.utcfromtimestamp(n/1000.0)


def datetime_to_java_sql_timestamp(d):
td = d - datetime.datetime(1970, 1, 1)
return td.microseconds // 1000 + (td.seconds + td.days * 24 * 3600) * 1000
return int(d.replace(tzinfo=datetime.timezone.utc).timestamp()*1000)


# FIXME This doesn't seem to be used anywhere in the code
Expand Down

0 comments on commit c32a62f

Please sign in to comment.