@@ -21,34 +21,34 @@ final class DateTimeSchema extends AbstractSchemaInnerParse implements SchemaInt
2121 public function from(\DateTimeImmutable $from): static
2222 {
2323 return $this->postParse(static function (\DateTimeImmutable $datetime) use ($from) {
24- if ($datetime < $from) {
25- throw new ErrorsException(
26- new Error(
27- self::ERROR_FROM_CODE,
28- self::ERROR_FROM_TEMPLATE,
29- ['from' => $from->format('c'), 'given' => $datetime->format('c')]
30- )
31- );
24+ if ($datetime >= $from) {
25+ return $datetime;
3226 }
3327
34- return $datetime;
28+ throw new ErrorsException(
29+ new Error(
30+ self::ERROR_FROM_CODE,
31+ self::ERROR_FROM_TEMPLATE,
32+ ['from' => $from->format('c'), 'given' => $datetime->format('c')]
33+ )
34+ );
3535 });
3636 }
3737
3838 public function to(\DateTimeImmutable $to): static
3939 {
4040 return $this->postParse(static function (\DateTimeImmutable $datetime) use ($to) {
41- if ($datetime > $to) {
42- throw new ErrorsException(
43- new Error(
44- self::ERROR_TO_CODE,
45- self::ERROR_TO_TEMPLATE,
46- ['to' => $to->format('c'), 'given' => $datetime->format('c')]
47- )
48- );
41+ if ($datetime <= $to) {
42+ return $datetime;
4943 }
5044
51- return $datetime;
45+ throw new ErrorsException(
46+ new Error(
47+ self::ERROR_TO_CODE,
48+ self::ERROR_TO_TEMPLATE,
49+ ['to' => $to->format('c'), 'given' => $datetime->format('c')]
50+ )
51+ );
5252 });
5353 }
5454
@@ -74,16 +74,16 @@ public function toString(): StringSchema
7474
7575 protected function innerParse(mixed $input): mixed
7676 {
77- if (!$input instanceof \DateTimeInterface) {
78- throw new ErrorsException(
79- new Error(
80- self::ERROR_TYPE_CODE,
81- self::ERROR_TYPE_TEMPLATE,
82- ['given' => $this->getDataType($input)]
83- )
84- );
77+ if ($input instanceof \DateTimeInterface) {
78+ return $input;
8579 }
8680
87- return $input;
81+ throw new ErrorsException(
82+ new Error(
83+ self::ERROR_TYPE_CODE,
84+ self::ERROR_TYPE_TEMPLATE,
85+ ['given' => $this->getDataType($input)]
86+ )
87+ );
8888 }
8989}
0 commit comments