Skip to content

Commit 20cdfc7

Browse files
committed
Add helper for parsing zoneless time strings.
1 parent a8b534c commit 20cdfc7

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

core/google/cloud/_helpers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,19 @@ def _date_from_iso8601_date(value):
251251
return datetime.datetime.strptime(value, '%Y-%m-%d').date()
252252

253253

254+
def _time_from_iso8601_time_naive(value):
255+
"""Convert a zoneless ISO8601 time string to naive datetime time
256+
257+
:type value: str
258+
:param value: The time string to convert
259+
260+
:rtype: :class:`datetime.time`
261+
:returns: A datetime time object created from the string
262+
263+
"""
264+
return datetime.datetime.strptime(value, '%H:%M:%S').time()
265+
266+
254267
def _rfc3339_to_datetime(dt_str):
255268
"""Convert a microsecond-precision timetamp to a native datetime.
256269

core/unit_tests/test__helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,18 @@ def test_todays_date(self):
265265
self.assertEqual(self._call_fut(TODAY.strftime("%Y-%m-%d")), TODAY)
266266

267267

268+
class Test___time_from_iso8601_time_naive(unittest.TestCase):
269+
270+
def _call_fut(self, value):
271+
from google.cloud._helpers import _time_from_iso8601_time_naive
272+
return _time_from_iso8601_time_naive(value)
273+
274+
def test_todays_date(self):
275+
import datetime
276+
WHEN = datetime.time(12, 9, 42)
277+
self.assertEqual(self._call_fut(("12:09:42")), WHEN)
278+
279+
268280
class Test__rfc3339_to_datetime(unittest.TestCase):
269281

270282
def _call_fut(self, dt_str):

0 commit comments

Comments
 (0)