File tree 2 files changed +16
-0
lines changed
2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,17 @@ public function __toString(): string
129
129
}
130
130
131
131
132
+ public function modify (string $ modifier = '' ): static
133
+ {
134
+ $ datetime = @parent ::modify ($ modifier );
135
+
136
+ if ($ datetime === false ) {
137
+ throw new Nette \InvalidArgumentException ("Failed to parse time string ' $ modifier' " );
138
+ }
139
+ return $ datetime ;
140
+ }
141
+
142
+
132
143
/**
133
144
* Creates a copy with a modified time.
134
145
*/
Original file line number Diff line number Diff line change @@ -25,3 +25,8 @@ $dolly2 = $date->modifyClone('+1 hour');
25
25
Assert::type (DateTime::class, $ dolly2 );
26
26
Assert::notSame ($ date , $ dolly2 );
27
27
Assert::notSame ((string ) $ date , (string ) $ dolly2 );
28
+
29
+ Assert::exception (
30
+ fn () => $ date ->modifyClone ('xx ' ),
31
+ Nette \InvalidArgumentException::class,
32
+ );
You can’t perform that action at this time.
0 commit comments