File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,16 @@ public function __toString(): string
129129 }
130130
131131
132+ public function modify (string $ modifier ): static
133+ {
134+ $ datetime = @parent ::modify ($ modifier ); // @ is escalated to exception
135+ if ($ datetime === false ) {
136+ throw new Nette \InvalidArgumentException (Helpers::getLastError ());
137+ }
138+ return $ datetime ;
139+ }
140+
141+
132142 /**
133143 * Creates a copy with a modified time.
134144 */
Original file line number Diff line number Diff line change @@ -25,3 +25,9 @@ $dolly2 = $date->modifyClone('+1 hour');
2525Assert::type (DateTime::class, $ dolly2 );
2626Assert::notSame ($ date , $ dolly2 );
2727Assert::notSame ((string ) $ date , (string ) $ dolly2 );
28+
29+ Assert::exception (
30+ fn () => $ date ->modifyClone ('xx ' ),
31+ PHP_VERSION_ID >= 80300 ? DateMalformedStringException::class : Nette \InvalidArgumentException::class,
32+ 'DateTime::modify(): Failed to parse %a% ' ,
33+ );
You can’t perform that action at this time.
0 commit comments