File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -870,8 +870,17 @@ public function subYears(int $years)
870870 */
871871 public function clamp (DateTimeInterface |self |string $ start , DateTimeInterface |self |string $ end ): static
872872 {
873- $ start = $ start instanceof DateTimeInterface ? $ start : new static ($ start , $ this ->timezone , $ this ->locale );
874- $ end = $ end instanceof DateTimeInterface ? $ end : new static ($ end , $ this ->timezone , $ this ->locale );
873+ if ($ start instanceof DateTimeInterface && ! $ start instanceof self) {
874+ $ start = static ::createFromInstance ($ start , $ this ->locale );
875+ } elseif (is_string ($ start )) {
876+ $ start = new static ($ start , $ this ->getTimezone (), $ this ->locale );
877+ }
878+
879+ if ($ end instanceof DateTimeInterface && ! $ end instanceof self) {
880+ $ end = static ::createFromInstance ($ end , $ this ->locale );
881+ } elseif (is_string ($ end )) {
882+ $ end = new static ($ end , $ this ->getTimezone (), $ this ->locale );
883+ }
875884
876885 if ($ end ->isBefore ($ start )) {
877886 throw I18nException::forInvalidClampRange ($ start ->toDateTimeString (), $ end ->toDateTimeString ());
You can’t perform that action at this time.
0 commit comments