Skip to content

Proposal for serializing datetime range for JSON-safe datetime range serialization #102

@Vishmayraj

Description

@Vishmayraj

Currently, there is no utility for serializing asyncpg Range datetime objects to JSON-safe strings. Raw datetime objects coming back from the database would crash if returned in a response body, and any future handling would require scattering .isoformat() calls across the codebase.

For the upcoming STAC and DCAT-AP connector that is in the GSOC ideas list, dct:temporal, dct:issued, dct:modified, and STAC item temporal extents all need clean ISO 8601 strings derived from phenomenonTime and resultTime ranges.

def serialize_datetime_range(range_value):
    if range_value is None:
        return None
    start = range_value.lower.isoformat() if range_value.lower else None
    end = range_value.upper.isoformat() if range_value.upper else None
    return {"start": start, "end": end}

I just wanted to ask about the '.isoformat()' everywhere, is that intentional, or is centralizing this the right direction?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions