Home / Function/ parse_datetime() — anthropic-sdk-python Function Reference

parse_datetime() — anthropic-sdk-python Function Reference

Architecture documentation for the parse_datetime() function in _datetime_parse.py from the anthropic-sdk-python codebase.

Function python AnthropicClient SyncAPI calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  f5a1b8d9_7ad8_89db_b3ec_43eb707e866a["parse_datetime()"]
  c8b41cc2_db36_3062_f709_8c907f559cd4["_datetime_parse.py"]
  f5a1b8d9_7ad8_89db_b3ec_43eb707e866a -->|defined in| c8b41cc2_db36_3062_f709_8c907f559cd4
  8e26344d_f1f2_4230_0dad_955f01f7a91f["parse_datetime()"]
  8e26344d_f1f2_4230_0dad_955f01f7a91f -->|calls| f5a1b8d9_7ad8_89db_b3ec_43eb707e866a
  813d6b44_1cbd_4a3f_a26b_fb9725d76e1e["_get_numeric()"]
  f5a1b8d9_7ad8_89db_b3ec_43eb707e866a -->|calls| 813d6b44_1cbd_4a3f_a26b_fb9725d76e1e
  78398841_7286_0ef9_ab08_aab8820ed275["_from_unix_seconds()"]
  f5a1b8d9_7ad8_89db_b3ec_43eb707e866a -->|calls| 78398841_7286_0ef9_ab08_aab8820ed275
  4184b9e7_258c_509c_5cf8_8e66635e6fed["_parse_timezone()"]
  f5a1b8d9_7ad8_89db_b3ec_43eb707e866a -->|calls| 4184b9e7_258c_509c_5cf8_8e66635e6fed
  style f5a1b8d9_7ad8_89db_b3ec_43eb707e866a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_utils/_datetime_parse.py lines 69–103

def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime:
    """
    Parse a datetime/int/float/string and return a datetime.datetime.

    This function supports time zone offsets. When the input contains one,
    the output uses a timezone with a fixed offset from UTC.

    Raise ValueError if the input is well formatted but not a valid datetime.
    Raise ValueError if the input isn't well formatted.
    """
    if isinstance(value, datetime):
        return value

    number = _get_numeric(value, "datetime")
    if number is not None:
        return _from_unix_seconds(number)

    if isinstance(value, bytes):
        value = value.decode()

    assert not isinstance(value, (float, int))

    match = datetime_re.match(value)
    if match is None:
        raise ValueError("invalid datetime format")

    kw = match.groupdict()
    if kw["microsecond"]:
        kw["microsecond"] = kw["microsecond"].ljust(6, "0")

    tzinfo = _parse_timezone(kw.pop("tzinfo"))
    kw_: Dict[str, Union[None, int, timezone]] = {k: int(v) for k, v in kw.items() if v is not None}
    kw_["tzinfo"] = tzinfo

    return datetime(**kw_)  # type: ignore

Subdomains

Called By

Frequently Asked Questions

What does parse_datetime() do?
parse_datetime() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_utils/_datetime_parse.py.
Where is parse_datetime() defined?
parse_datetime() is defined in src/anthropic/_utils/_datetime_parse.py at line 69.
What does parse_datetime() call?
parse_datetime() calls 3 function(s): _from_unix_seconds, _get_numeric, _parse_timezone.
What calls parse_datetime()?
parse_datetime() is called by 1 function(s): parse_datetime.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free