Skip to main content

TagDateTime

This class provides a mechanism for handling datetime objects within a JSON tagging system. It identifies datetime instances, converts them to HTTP-formatted date strings for JSON serialization, and parses them back into Python datetime objects during deserialization.

Attributes

AttributeTypeDescription
keystring = dThe unique tag identifier used in the JSON structure to represent datetime objects.

Methods


check()

@classmethod
def check(
value: t.Any
) - > bool

Checks if the provided value is an instance of a datetime object.

Parameters

NameTypeDescription
valuet.AnyThe object to validate against the datetime type

Returns

TypeDescription
boolTrue if the value is a datetime instance, False otherwise

to_json()

@classmethod
def to_json(
value: t.Any
) - > t.Any

Converts a datetime object into a standardized HTTP date string format for JSON serialization.

Parameters

NameTypeDescription
valuet.AnyThe datetime object to be serialized into a string

Returns

TypeDescription
t.AnyAn HTTP-formatted date string representing the input datetime

to_python()

@classmethod
def to_python(
value: t.Any
) - > t.Any

Parses an HTTP-formatted date string back into a Python datetime object.

Parameters

NameTypeDescription
valuet.AnyThe serialized date string to be parsed

Returns

TypeDescription
t.AnyA datetime object reconstructed from the serialized string