Skip to main content

TagDateTime

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

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 be validated 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 formatted

Returns​

TypeDescription
t.AnyA string representing the date in HTTP format

to_python()​

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

Parses an HTTP date string and converts it back into a Python datetime object.

Parameters​

NameTypeDescription
valuet.AnyThe HTTP date string to be parsed

Returns​

TypeDescription
t.AnyA datetime object reconstructed from the input string