Skip to content

Rewrite validation function time_range_possibilities #479

@hf-krechan

Description

@hf-krechan

Es geht um diese Codezeilen:

def time_range_possibilities(cls, endzeitpunkt: Optional[datetime], values: Dict[str, Any]) -> Optional[datetime]:
"""
An address is valid if it contains a postfach XOR (a strasse AND hausnummer).
This functions checks for these conditions of a valid address.
"""
if (
values["einheit"]
and values["dauer"]
and not (values["startdatum"] or values["enddatum"] or values["startzeitpunkt"] or endzeitpunkt)
):
return endzeitpunkt
if (
values["startdatum"]
and values["enddatum"]
and not (values["einheit"] or values["dauer"] or values["startzeitpunkt"] or endzeitpunkt)
):
return endzeitpunkt
if (
values["startzeitpunkt"]
and endzeitpunkt
and not (values["einheit"] or values["dauer"] or values["startdatum"] or values["enddatum"])
):
return endzeitpunkt
raise ValueError(
"""
Please choose from one of the three possibilities to specify the timerange:
- einheit and dauer
- startdatum and enddatum
- startzeitpunkt and endzeitpunkt
"""
)

todo: rewrite this to be more readable; just migrated to pydantic v2 without thinking too much about it
Es geht um die time_range_possibilities in dem Modul src/bo4e/com/zeitraum.py

PS: Der Docstring ist auch falsch

Originally posted by @hf-krechan in #476 (comment)

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