MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / parse_datetime

Function parse_datetime

openlibrary/api.py:282–292  ·  view source on GitHub ↗

Parses ISO datetime formatted string.:: >>> parse_datetime("2009-01-02T03:04:05.006789") datetime.datetime(2009, 1, 2, 3, 4, 5, 6789)

(value)

Source from the content-addressed store, hash-verified

280
281
282def parse_datetime(value):
283 """Parses ISO datetime formatted string.::
284
285 >>> parse_datetime("2009-01-02T03:04:05.006789")
286 datetime.datetime(2009, 1, 2, 3, 4, 5, 6789)
287 """
288 if isinstance(value, datetime.datetime):
289 return value
290 else:
291 tokens = re.split(r"-|T|:|\.| ", value)
292 return datetime.datetime(*map(int, tokens))
293
294
295class Text(str):

Callers 1

unmarshalFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected