Skip to content

Commit

Permalink
Fix datetime encode/decode (#53)
Browse files Browse the repository at this point in the history
Issues:
* The encode assumed that the given datetime is in UTC, rather then **convert** it to UTC
* The decode didn't return a UTC timezoned time. which caused bugs when writing a timestamp from nginx, and reading via v3io-py the time object returned was incorrect.
  • Loading branch information
talIguaz authored Oct 12, 2020
1 parent 3a7d9d9 commit 593b53d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def _get_float_array():
'list_with_floats': [10.5, 20.5, 30.5],
'array_with_ints': _get_int_array(),
'array_with_floats': _get_float_array(),
'now': datetime.datetime.utcnow()
'now': datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_client_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def _get_float_array():
'list_with_floats': [10.5, 20.5, 30.5],
'array_with_ints': _get_int_array(),
'array_with_floats': _get_float_array(),
'now': datetime.datetime.utcnow()
'now': datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_client_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def _get_float_array():
'list_with_floats': [10.5, 20.5, 30.5],
'array_with_ints': _get_int_array(),
'array_with_floats': _get_float_array(),
'now': datetime.datetime.utcnow()
'now': datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
}
}

Expand Down
4 changes: 2 additions & 2 deletions v3io/dataplane/kv_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def _get_timestamp_from_datetime_py3(dt):
return dt.replace(tzinfo=datetime.timezone.utc).timestamp()
return dt.astimezone(datetime.timezone.utc).timestamp()


def _get_timestamp_from_datetime_py2(dt):
Expand Down Expand Up @@ -35,4 +35,4 @@ def decode(encoded_dt):

timestamp = int(seconds_str) + (int(nanoseconds_str) / 10e9)

return datetime.datetime.utcfromtimestamp(timestamp)
return datetime.datetime.fromtimestamp(timestamp, datetime.timezone.utc)

0 comments on commit 593b53d

Please sign in to comment.