-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Move TimestampNanoSeconds to api_core #4979
Move TimestampNanoSeconds to api_core #4979
Conversation
d0a57a8
to
a873e71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the changes to spanner in a separate PR?
nanosecond=nanos, tzinfo=UTC) | ||
|
||
|
||
class _UTC(datetime.tzinfo): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
nanos = kw.pop('nanosecond', 0) | ||
if nanos > 0: | ||
if 'microsecond' in kw: | ||
raise TypeError( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
__slots__ = ('_nanosecond',) | ||
|
||
# pylint: disable=arguments-differ | ||
def __new__(cls, *args, **kw): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return self._nanosecond | ||
|
||
def rfc3339(self): | ||
"""RFC 3339-compliant timestamp. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def rfc3339(self): | ||
"""RFC 3339-compliant timestamp. | ||
|
||
:rtype: str |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
if self._nanosecond == 0: | ||
return to_rfc3339(self) | ||
nanos = str(self._nanosecond).rstrip('0') | ||
return '%s.%sZ' % (self.strftime(_RFC3339_NO_FRACTION), nanos) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -13,6 +13,7 @@ | |||
# limitations under the License. | |||
|
|||
import datetime | |||
import unittest |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
d386fd0
to
414f86a
Compare
414f86a
to
63fc6be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loooking pretty close, just a few more nits.
|
||
|
||
def test_timestampwithnanos_from_rfc3339_wo_fraction(): | ||
from google.api_core import datetime_helpers |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def test_timestampwithnanos_from_rfc3339_wo_fraction(): | ||
from google.api_core import datetime_helpers | ||
|
||
klass = datetime_helpers.TimestampWithNanoseconds |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
d02ed93
to
ccd3415
Compare
ccd3415
to
770aecd
Compare
@@ -179,3 +179,71 @@ def to_rfc3339(value, ignore_zone=True): | |||
value = value.replace(tzinfo=None) - value.utcoffset() | |||
|
|||
return value.strftime(_RFC3339_MICROS) | |||
|
|||
|
|||
class TimestampWithNanoseconds(datetime.datetime): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Closes #4829