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
| Attribute | Type | Description |
|---|---|---|
| key | string = d | The 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The object to be validated against the datetime type |
Returns
| Type | Description |
|---|---|
bool | True 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The datetime object to be formatted |
Returns
| Type | Description |
|---|---|
t.Any | A 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The HTTP date string to be parsed |
Returns
| Type | Description |
|---|---|
t.Any | A datetime object reconstructed from the input string |