Skip to content

Commit be758d1

Browse files
update
1 parent b3d6a5e commit be758d1

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

src/Time.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* - Add/subtract helpers: addSeconds/Minutes/Hours/Days/Weeks/Months/Years and sub*
2020
* - Formatting: format(), toDateTimeString(), toJsTimer(), timestamp()
2121
* - Range helper: dateRange()
22-
* - Text features/config: config(), greeting (via greeting), timeAgo (via timeAgo)
22+
* - Text features/config: config(), greeting (via __greeting), timeAgo (via __timeAgo)
2323
*
2424
* All methods are documented at their definitions for clarity.
2525
*/
@@ -91,7 +91,7 @@ public function __construct($date = null, $timezone = null)
9191

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

@@ -467,7 +467,7 @@ public static function config(?array $options = [])
467467
* Get the stored date time
468468
* @return int
469469
*/
470-
public function getDate()
470+
public function __getDate()
471471
{
472472
return (int) $this->date;
473473
}
@@ -476,63 +476,63 @@ public function getDate()
476476
* Get the number of seconds between the stored time and the current time.
477477
* @return mixed
478478
*/
479-
public function getSecond()
479+
public function __getSecond()
480480
{
481-
return $this->timeDifference('sec');
481+
return $this->__timeDifference('sec');
482482
}
483483

484484
/**
485485
* Get the number of minutes between the stored time and the current time.
486486
* @return mixed
487487
*/
488-
public function getMin()
488+
public function __getMin()
489489
{
490-
return $this->timeDifference('mins');
490+
return $this->__timeDifference('mins');
491491
}
492492

493493
/**
494494
* Get the number of hours between the stored time and the current time.
495495
* @return mixed
496496
*/
497-
public function getHour()
497+
public function __getHour()
498498
{
499-
return $this->timeDifference('hour');
499+
return $this->__timeDifference('hour');
500500
}
501501

502502
/**
503503
* Get the number of days between the stored time and the current time.
504504
* @return mixed
505505
*/
506-
public function getDay()
506+
public function __getDay()
507507
{
508-
return $this->timeDifference('days');
508+
return $this->__timeDifference('days');
509509
}
510510

511511
/**
512512
* Get the number of weeks between the stored time and the current time.
513513
* @return mixed
514514
*/
515-
public function getWeek()
515+
public function __getWeek()
516516
{
517-
return $this->timeDifference('weeks');
517+
return $this->__timeDifference('weeks');
518518
}
519519

520520
/**
521521
* Get the number of months between the stored time and the current time.
522522
* @return mixed
523523
*/
524-
public function getMonth()
524+
public function __getMonth()
525525
{
526-
return $this->timeDifference('month');
526+
return $this->__timeDifference('month');
527527
}
528528

529529
/**
530530
* Get the number of years between the stored time and the current time.
531531
* @return mixed
532532
*/
533-
public function getYear()
533+
public function __getYear()
534534
{
535-
return $this->timeDifference('year');
535+
return $this->__timeDifference('year');
536536
}
537537

538538
/**
@@ -541,7 +541,7 @@ public function getYear()
541541
*
542542
* @return string
543543
*/
544-
public function greeting($date = 'now')
544+
public function __greeting($date = 'now')
545545
{
546546
$clone = $this->clone();
547547
$clone->date = TimeHelper::setPassedDate($date);
@@ -576,7 +576,7 @@ public function greeting($date = 'now')
576576
*
577577
* @return mixed
578578
*/
579-
public function timeDifferenceBetween($firstDate, $lastDate, $mode = null)
579+
public function __timeDifferenceBetween($firstDate, $lastDate, $mode = null)
580580
{
581581
$clone = $this->clone();
582582

@@ -597,7 +597,7 @@ public function timeDifferenceBetween($firstDate, $lastDate, $mode = null)
597597
*
598598
* @return mixed
599599
*/
600-
public function timeDifference($mode = null)
600+
public function __timeDifference($mode = null)
601601
{
602602
$clone = $this->clone();
603603

@@ -621,17 +621,17 @@ public function timeDifference($mode = null)
621621
*
622622
* @return string
623623
*/
624-
public function timeAgo($mode = null)
624+
public function __timeAgo($mode = null)
625625
{
626-
$diff = $this->timeDifference();
626+
$diff = $this->__timeDifference();
627627

628628
$minutes = $diff['mins'];
629629
$seconds = $diff['sec'];
630630
$hours = $diff['hour'];
631631
$days = $diff['days'];
632632
$weeks = $diff['weeks'];
633633
$years = $diff['year'];
634-
$date = $this->getDate();
634+
$date = $this->__getDate();
635635
$text = self::getText();
636636

637637
if ($days === 0 && $hours === 0 && $minutes < 1) {
@@ -732,8 +732,8 @@ public function __debugInfo(): array
732732
'formatted' => date('Y-m-d H:i:s', $time),
733733
'timezone' => (string) ($this->timezoneName ?? $this->timezone),
734734
'utc_offset' => ($this->utcOffset ?? date('(P)', $time)),
735-
'greeting' => $this->greeting($time),
736-
'time_ago_short' => $this->timeAgo('short'),
735+
'greeting' => $this->__greeting($time),
736+
'time_ago_short' => $this->__timeAgo('short'),
737737
];
738738
}
739739
}

src/Traits/TimeExtraTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public function isToday(): bool
356356
*/
357357
public function isTomorrow(): bool
358358
{
359-
$tz = new DateTimeZone((string) $this->getTimezone());
359+
$tz = new DateTimeZone((string) $this->__getTimezone());
360360
$tomorrow = new DateTime('tomorrow', $tz);
361361
$cur = $this->dtInTz((int) $this->date)->format('Y-m-d');
362362
return $tomorrow->format('Y-m-d') === $cur;

src/Traits/TimeTrait.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -268,23 +268,23 @@ private static function nonExistMethod($method = null, $args = null, $clone = nu
268268

269269
// create correct method name
270270
$method = match ($name) {
271-
'greetings', 'greeting' => 'greeting',
271+
'greetings', 'greeting' => '__greeting',
272272
'tojs', 'jstimer' => 'toJsTimer',
273-
's', 'sec', 'secs', 'getseconds', 'getsec' => 'getSecond',
274-
'min', 'mins', 'getminute', 'getminutes', 'getmin', 'getmins' => 'getMin',
275-
'hr', 'hrs', 'hour', 'hours', 'gethr', 'gethours', 'gethour' => 'getHour',
276-
'getday', 'getdays', 'getd', 'day', 'days' => 'getDay',
277-
'getweek', 'getweeks', 'week', 'weeks', 'getw' => 'getWeek',
278-
'getmonths', 'getmonth', 'getm', 'month', 'months' => 'getMonth',
279-
'getyr', 'getyears', 'getyear', 'year', 'years', 'yr', 'yrs', 'y' => 'getYear',
280-
'time', 'gettimes', 'gettime', 'getdate' => 'getDate',
281-
'setdate' => 'setDate',
282-
'gettimezone' => 'getTimezone',
283-
'settimezone' => 'setTimezone',
284-
'diffbetween', 'timediffbetween' => 'timeDifferenceBetween',
285-
'diff', 'timediff' => 'timeDifference',
273+
's', 'sec', 'secs', 'getseconds', 'getsec' => '__getSecond',
274+
'min', 'mins', 'getminute', 'getminutes', 'getmin', 'getmins' => '__getMin',
275+
'hr', 'hrs', 'hour', 'hours', 'gethr', 'gethours', 'gethour' => '__getHour',
276+
'getday', 'getdays', 'getd', 'day', 'days' => '__getDay',
277+
'getweek', 'getweeks', 'week', 'weeks', 'getw' => '__getWeek',
278+
'getmonths', 'getmonth', 'getm', 'month', 'months' => '__getMonth',
279+
'getyr', 'getyears', 'getyear', 'year', 'years', 'yr', 'yrs', 'y' => '__getYear',
280+
'time', 'gettimes', 'gettime', 'getdate' => '__getDate',
281+
'setdate' => '__setDate',
282+
'gettimezone' => '__getTimezone',
283+
'settimezone' => '__setTimezone',
284+
'diffbetween', 'timediffbetween' => '__timeDifferenceBetween',
285+
'diff', 'timediff' => '__timeDifference',
286286
'daterange', 'range' => 'dateRange',
287-
'ago', 'timeago' => 'timeAgo',
287+
'ago', 'timeago' => '__timeAgo',
288288
'addsecond' => 'addSeconds',
289289
'subsecond' => 'subSeconds',
290290
'addminute' => 'addMinutes',

tests/time.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
dd(
3939
$time2,
40-
$time3::greetings('24 Jan 2025 14:00:00'),
40+
$time3,
4141
);
4242

4343
dd(

0 commit comments

Comments
 (0)