-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converting _datetime_from_millis to handle microseconds.
Also making it require a float (or int) instead of bailing out for NoneType. Changing the use of the method in bigquery to not pass potentially null values and to multiply by 1000.0 (convert from millis to micros). Also updating micros -> datetime conversion in datastore to use the newly converted method.
- Loading branch information
Showing
5 changed files
with
40 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
|
||
import six | ||
|
||
from gcloud._helpers import _datetime_from_millis | ||
from gcloud._helpers import _datetime_from_microseconds | ||
from gcloud._helpers import _millis_from_datetime | ||
from gcloud.exceptions import NotFound | ||
|
||
|
@@ -116,7 +116,10 @@ def created(self): | |
:rtype: ``datetime.datetime``, or ``NoneType`` | ||
:returns: the creation time (None until set from the server). | ||
""" | ||
return _datetime_from_millis(self._properties.get('creationTime')) | ||
creation_time = self._properties.get('creationTime') | ||
if creation_time is not None: | ||
# creation_time will be in milliseconds. | ||
return _datetime_from_microseconds(1000.0 * creation_time) | ||
|
||
@property | ||
def etag(self): | ||
|
@@ -134,7 +137,10 @@ def modified(self): | |
:rtype: ``datetime.datetime``, or ``NoneType`` | ||
:returns: the modification time (None until set from the server). | ||
""" | ||
return _datetime_from_millis(self._properties.get('lastModifiedTime')) | ||
modified_time = self._properties.get('lastModifiedTime') | ||
if modified_time is not None: | ||
# modified_time will be in milliseconds. | ||
return _datetime_from_microseconds(1000.0 * modified_time) | ||
|
||
@property | ||
def num_bytes(self): | ||
|
@@ -212,7 +218,10 @@ def expires(self): | |
:rtype: ``datetime.datetime``, or ``NoneType`` | ||
:returns: the expiration time, or None | ||
""" | ||
return _datetime_from_millis(self._properties.get('expirationTime')) | ||
expiration_time = self._properties.get('expirationTime') | ||
if expiration_time is not None: | ||
# expiration_time will be in milliseconds. | ||
return _datetime_from_microseconds(1000.0 * expiration_time) | ||
|
||
@expires.setter | ||
def expires(self, value): | ||
|
@@ -727,7 +736,8 @@ def _bool_from_json(value, field): | |
|
||
def _datetime_from_json(value, field): | ||
if _not_null(value, field): | ||
return _datetime_from_millis(float(value)) | ||
# Field value will be in milliseconds. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dhermes
Author
Contributor
|
||
return _datetime_from_microseconds(1000.0 * float(value)) | ||
|
||
|
||
def _record_from_json(value, field): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@dhermes I'm getting values out of BigQuery in seconds. So * 1000.0 is not enough - it needs to be * 1000000.0 to work. However, I'm not sure if that is a bug in the BigQuery API or a bug in this client library.