Skip to content

Commit f4c51cf

Browse files
committed
Rename strptime format constant:
- Ref. correct RFC. - Private - Add '_MICROS' to indicate which format from the sheaf allowed by the RFC. Addresses points 1 and 2 from: #816 (comment). and: #816 (comment)
1 parent b0209de commit f4c51cf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

gcloud/pubsub/message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import pytz
2121

22-
RFC3369 = '%Y-%m-%dT%H:%M:%S.%fZ'
22+
_RFC3339_MICROS = '%Y-%m-%dT%H:%M:%S.%fZ'
2323

2424

2525
class Message(object):
@@ -54,13 +54,13 @@ def timestamp(self):
5454
"""Return timestamp from attributes, if passed.
5555
5656
:rtype: datetime
57-
:returns: timestamp (in UTC timezone) parsed from RFC 3369 timestamp
57+
:returns: timestamp (in UTC timezone) parsed from RFC 3339 timestamp
5858
:raises: ValueError if timestamp not in ``attributes``, or malformed
5959
"""
6060
stamp = self.attributes.get('timestamp')
6161
if stamp is None:
6262
raise ValueError('No timestamp')
63-
return datetime.datetime.strptime(stamp, RFC3369).replace(
63+
return datetime.datetime.strptime(stamp, _RFC3339_MICROS).replace(
6464
tzinfo=pytz.UTC)
6565

6666
@classmethod

gcloud/pubsub/test_message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ def _to_fail():
9191

9292
def test_timestamp_w_timestamp_in_attributes(self):
9393
from datetime import datetime
94-
import pytz
94+
from pytz import utc
95+
from gcloud.pubsub.message import _RFC3339_MICROS
9596
DATA = b'DEADBEEF'
9697
MESSAGE_ID = b'12345'
9798
TIMESTAMP = '2015-04-10T18:42:27.131956Z'
98-
RFC3369 = '%Y-%m-%dT%H:%M:%S.%fZ'
99-
naive = datetime.strptime(TIMESTAMP, RFC3369)
100-
timestamp = naive.replace(tzinfo=pytz.utc)
99+
naive = datetime.strptime(TIMESTAMP, _RFC3339_MICROS)
100+
timestamp = naive.replace(tzinfo=utc)
101101
ATTRS = {'timestamp': TIMESTAMP}
102102
message = self._makeOne(data=DATA, message_id=MESSAGE_ID,
103103
attributes=ATTRS)

0 commit comments

Comments
 (0)