forked from mistralai/client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatetimes.py
More file actions
23 lines (18 loc) · 855 Bytes
/
Copy pathdatetimes.py
File metadata and controls
23 lines (18 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from datetime import datetime
import sys
def parse_datetime(datetime_string: str) -> datetime:
"""
Convert a RFC 3339 / ISO 8601 formatted string into a datetime object.
Python versions 3.11 and later support parsing RFC 3339 directly with
datetime.fromisoformat(), but for earlier versions, this function
encapsulates the necessary extra logic.
"""
# Python 3.11 and later can parse RFC 3339 directly
if sys.version_info >= (3, 11):
return datetime.fromisoformat(datetime_string)
# For Python 3.10 and earlier, a common ValueError is trailing 'Z' suffix,
# so fix that upfront.
if datetime_string.endswith("Z"):
datetime_string = datetime_string[:-1] + "+00:00"
return datetime.fromisoformat(datetime_string)