pydantic-core icon indicating copy to clipboard operation
pydantic-core copied to clipboard

Support `FutureDate/Datetime` and `PastDate/Datetime`

Open samuelcolvin opened this issue 2 years ago • 4 comments

This will require us to add support for now() and today() to speedate, see https://github.com/pydantic/speedate/issues/19.

Required to for https://github.com/pydantic/pydantic/issues/4330.

samuelcolvin avatar Aug 12 '22 14:08 samuelcolvin

I think I don't understand why it's needed. Doesn't

SchemaValidator(
    {
        'type': 'typed-dict',
        'fields': {
            'future_datetime': {
                'schema': {'type': 'datetime', 'gt': datetime.now()},
            },
        },
    }
)

already tackle this issue?

PrettyWood avatar Aug 30 '22 11:08 PrettyWood

no because we create the schema once and use it many times, perhaps days later.

samuelcolvin avatar Aug 30 '22 11:08 samuelcolvin

Right...sorry not enough sleep! 🤦 And what would be the desired API? A FutureDatetimeSchema with only le and lt as constraints? Or do we allow "magic" strings as boundaries (e.g. le: 'today')? They could also probably be sentinels

PrettyWood avatar Aug 30 '22 12:08 PrettyWood

Well FutureDate, Datetime, PastDate and Datetime can all be bear types, no further configuration is required.

We'll also want condatetime etc., but we're also going to support the annotated-types allowing

class MyClass:
    ts: Annotated[datetime, Gt(datetime(2022, 8, 30, 12, 0))]

samuelcolvin avatar Aug 30 '22 12:08 samuelcolvin