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
| 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 validate 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 serialized into a string |
Returns
| Type | Description |
|---|---|
t.Any | An 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The serialized date string to be parsed |
Returns
| Type | Description |
|---|---|
t.Any | A datetime object reconstructed from the serialized string |