Skip to content

Commit d9f9673

Browse files
update
1 parent 2b0bd49 commit d9f9673

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/Time.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ public function __construct($date = null, $timezone = null)
8989
$this->timezone = $clone->timezone;
9090
}
9191

92-
// clone copy of self
93-
if(!self::isTimeInstance()){
94-
self::$staticData = $this->copy();
95-
}
92+
// Always refresh the static instance binding to the latest constructed instance
93+
// so subsequent static calls use the most recent timezone/date context
94+
self::$staticData = $this->copy();
9695
}
9796

9897
/**
@@ -123,7 +122,12 @@ public function __call($name, $args)
123122
*/
124123
public static function __callStatic($name, $args)
125124
{
126-
return self::nonExistMethod($name, $args, static::$staticData);
125+
// Use a cloned bound instance if available; otherwise seed a fresh one
126+
$instance = static::$staticData instanceof static
127+
? static::$staticData->copy()
128+
: new static();
129+
130+
return self::nonExistMethod($name, $args, $instance);
127131
}
128132

129133
/**

src/Traits/TimeTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ private function buildTimeModifier($mode = 'day', $value = 0, $sub = false)
9999
$clone->date = strtotime("{$date} {$sign} {$value}{$text}");
100100
$clone->timestamp = $clone->buildTimePrint();
101101

102+
// keep static binding in sync with latest produced clone
103+
static::$staticData = $clone->copy();
104+
102105
return $clone;
103106
}
104107

tests/time.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
// ];
3737

3838
dd(
39-
$time2,
40-
$time3::startofYears(),
41-
$time4,
39+
$time->getTimezone(),
40+
$time2->getTimezone(),
41+
$time3->now(),
42+
$time4->getTimezone(),
4243
);
4344

4445
dd(

0 commit comments

Comments
 (0)