Skip to content

omnipy.components.isa.models.validators

Validation helpers shared by ISA schema models.

These helpers support ISA-JSON Investigation/Study/Assay metadata parsing in Omnipy.

FUNCTION DESCRIPTION
date_to_iso_format

Convert date-like values to their ISO-8601 string form.

date_to_iso_format

date_to_iso_format(data: datetime | date | pyd.constr(max_length=0))

Convert date-like values to their ISO-8601 string form.

PARAMETER DESCRIPTION
data

Value to normalize. date and datetime instances are converted with isoformat(), while empty-string constrained values are returned unchanged.

TYPE: datetime | date | pyd.constr(max_length=0)

RETURNS DESCRIPTION

ISO-8601 formatted string for date-like inputs, otherwise the original value.

Source code in src/omnipy/components/isa/models/validators.py
def date_to_iso_format(data: Union[datetime, date, pyd.constr(max_length=0)]):
    """Convert date-like values to their ISO-8601 string form.

    Args:
        data: Value to normalize. ``date`` and ``datetime`` instances are
            converted with ``isoformat()``, while empty-string constrained
            values are returned unchanged.

    Returns:
        ISO-8601 formatted string for date-like inputs, otherwise the original
        value.
    """

    if isinstance(data, date) or isinstance(data, datetime):
        return data.isoformat()
    return data