Skip to content

Commit 2b0bd49

Browse files
update
1 parent 02a6a76 commit 2b0bd49

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/Time.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public function __construct($date = null, $timezone = null)
9090
}
9191

9292
// clone copy of self
93-
// if(!self::isTimeInstance()){
94-
// self::$staticData = $this->copy();
95-
// }
93+
if(!self::isTimeInstance()){
94+
self::$staticData = $this->copy();
95+
}
9696
}
9797

9898
/**
@@ -123,11 +123,7 @@ public function __call($name, $args)
123123
*/
124124
public static function __callStatic($name, $args)
125125
{
126-
$instance = (self::$staticData instanceof self)
127-
? self::$staticData->copy()
128-
: new self();
129-
130-
return self::nonExistMethod($name, $args, $instance);
126+
return self::nonExistMethod($name, $args, static::$staticData);
131127
}
132128

133129
/**

src/Traits/TimeTrait.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace Tamedevelopers\Support\Traits;
66

7+
use Closure;
78
use DateTime;
89
use Tamedevelopers\Support\Str;
10+
use Tamedevelopers\Support\Time;
911
use Tamedevelopers\Support\Country;
1012
use Tamedevelopers\Support\Capsule\TimeHelper;
1113
use Tamedevelopers\Support\Capsule\CustomException;
@@ -16,8 +18,19 @@
1618
*
1719
* Internal helpers used by the Time class for cloning, timezone handling,
1820
* and common operations. Public API is provided by Time and dynamic dispatch.
21+
* @property mixed $staticData
1922
*/
2023
trait TimeTrait{
24+
25+
/**
26+
* Determine whether the static context already holds a Time instance.
27+
*
28+
* @return bool
29+
*/
30+
static protected function isTimeInstance()
31+
{
32+
return static::$staticData instanceof self;
33+
}
2134

2235
/**
2336
* Clone a new instance of the owning class.
@@ -294,7 +307,7 @@ private static function nonExistMethod($method = null, $args = null, $clone = nu
294307
'endofweek' => 'endOfWeek',
295308
'startofmonth' => 'startOfMonth',
296309
'endofmonth' => 'endOfMonth',
297-
'startofyear' => 'startOfYear',
310+
'startofyear', 'startofyears' => 'startOfYear',
298311
'endofyear' => 'endOfYear',
299312
'issameday' => 'isSameDay',
300313
'issamemonth' => 'isSameMonth',

tests/time.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
$time2 = (new Time)->setTimezone('America/St_Barthelemy');
2323
$time3 = (new Time)->setTimezone('Indian/Antananarivo');
24-
// $time4 = TameTime('first day of December 2008', 'Pacific/Pago_Pago');
24+
$time4 = TameTime('first day of December 2008', 'Pacific/Pago_Pago');
2525

2626
// [
2727
// $time->toJsTimer('24 Jan 2025 14:00:00'),
@@ -37,7 +37,8 @@
3737

3838
dd(
3939
$time2,
40-
$time3::greetings('24 Jan 2025 14:00:00'),
40+
$time3::startofYears(),
41+
$time4,
4142
);
4243

4344
dd(

0 commit comments

Comments
 (0)