File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -844,6 +844,40 @@ class Offer
844844> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look
845845> [in the Introduction section](#introduction).
846846
847+ # ## Input format
848+
849+ Since API Platform 5.1, the `format` argument of the ORM and ODM `DateFilter` restricts the accepted
850+ input to a single
851+ [date format](https://www.php.net/manual/en/datetime.format.php#refsect1-datetime.format-parameters):
852+
853+ ` ` ` php
854+ <?php
855+ // api/src/ApiResource/Article.php
856+ namespace App\A piResource;
857+
858+ use ApiPlatform\D octrine\O rm\F ilter\D ateFilter;
859+ use ApiPlatform\M etadata\G etCollection;
860+ use ApiPlatform\M etadata\Q ueryParameter;
861+
862+ #[GetCollection(
863+ parameters: [
864+ 'publishedAt' => new QueryParameter(filter: new DateFilter(format: 'd/m/Y')),
865+ ],
866+ )]
867+ class Article
868+ {
869+ // ...
870+ }
871+ ` ` `
872+
873+ A request such as `/articles?publishedAt[before]=20/03/2022` is then parsed with
874+ `DateTimeImmutable::createFromFormat`. Parsing is strict : the time part resets to midnight when the
875+ format does not define it, and values that overflow (such as `32/03/2022`) or carry trailing data
876+ are rejected. Like any other invalid date, a rejected value is ignored by the filter. The documented
877+ JSON Schema and OpenAPI type of the parameter is a plain `string`, without `format : date`.
878+
879+ Without `format`, the filter accepts any value supported by the `\DateTime` constructor.
880+
847881# ## Date Filter using the ApiFilter Attribute Syntax (not recommended)
848882
849883Basically the ApiFilter declares the correct service under the hood. We recommend to use
You can’t perform that action at this time.
0 commit comments