Skip to content

Commit b3d6a5e

Browse files
update
1 parent 38acc29 commit b3d6a5e

File tree

4 files changed

+64
-59
lines changed

4 files changed

+64
-59
lines changed

src/Time.php

Lines changed: 33 additions & 33 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
*/
@@ -81,8 +81,8 @@ public function __construct($date = null, $timezone = null)
8181
$this->timezone = TimeHelper::configureAndSetTimezone($timezone);
8282
}
8383

84-
if(empty($this->date)){
85-
$clone = $this->__setDate($date);
84+
if (empty($this->date)) {
85+
$clone = $this->setDate($date);
8686

8787
$this->date = $clone->date;
8888
$this->timestamp = $clone->timestamp;
@@ -91,7 +91,7 @@ public function __construct($date = null, $timezone = null)
9191

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

@@ -288,7 +288,7 @@ public function subYears($value = 0)
288288
*/
289289
public function createFromFormat($datetime, $format = 'm/d/Y h:i:sa')
290290
{
291-
return $this->__setDate(
291+
return $this->setDate(
292292
self::timestamp($datetime, $format)
293293
);
294294
}
@@ -300,7 +300,7 @@ public function createFromFormat($datetime, $format = 'm/d/Y h:i:sa')
300300
*/
301301
public function date($date)
302302
{
303-
return $this->__setDate($date);
303+
return $this->setDate($date);
304304
}
305305

306306
/**
@@ -320,7 +320,7 @@ public function now()
320320
*/
321321
public function today()
322322
{
323-
return $this->__setDate('today');
323+
return $this->setDate('today');
324324
}
325325

326326
/**
@@ -330,7 +330,7 @@ public function today()
330330
*/
331331
public function yesterday()
332332
{
333-
return $this->__setDate('yesterday');
333+
return $this->setDate('yesterday');
334334
}
335335

336336
/**
@@ -346,8 +346,8 @@ public function yesterday()
346346
*/
347347
public function format($format = null, $date = null)
348348
{
349-
if(!empty($date)){
350-
$clone = $this->__setDate($date);
349+
if (!empty($date)) {
350+
$clone = $this->setDate($date);
351351
$this->date = $clone->date;
352352
}
353353

@@ -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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait TimeExtraTrait
2525
private function dtInTz(int $timestamp): DateTime
2626
{
2727
$dt = new DateTime('@' . $timestamp); // start from UTC-based ts
28-
$dt->setTimezone(new DateTimeZone((string) $this->__getTimezone()));
28+
$dt->setTimezone(new DateTimeZone((string) $this->getTimezone()));
2929
return $dt;
3030
}
3131

@@ -343,7 +343,7 @@ public function diffInSeconds($otherDate): int
343343
*/
344344
public function isToday(): bool
345345
{
346-
$now = new DateTime('now', new DateTimeZone((string) $this->__getTimezone()));
346+
$now = new DateTime('now', new DateTimeZone((string) $this->getTimezone()));
347347
$today = $now->format('Y-m-d');
348348
$cur = $this->dtInTz((int) $this->date)->format('Y-m-d');
349349
return $today === $cur;
@@ -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;
@@ -369,7 +369,7 @@ public function isTomorrow(): bool
369369
*/
370370
public function isYesterday(): bool
371371
{
372-
$tz = new DateTimeZone((string) $this->__getTimezone());
372+
$tz = new DateTimeZone((string) $this->getTimezone());
373373
$yesterday = new DateTime('yesterday', $tz);
374374
$cur = $this->dtInTz((int) $this->date)->format('Y-m-d');
375375
return $yesterday->format('Y-m-d') === $cur;

src/Traits/TimeTrait.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ private function buildTimeModifier($mode = 'day', $value = 0, $sub = false)
107107
*
108108
* @return string
109109
*/
110-
public function __getTimezone()
110+
public function getTimezone()
111111
{
112-
if(empty($this->timezone)){
113-
$this->__setTimezone();
112+
if (empty($this->timezone)) {
113+
$this->setTimezone();
114114
}
115115

116116
return $this->timezone;
@@ -122,7 +122,7 @@ public function __getTimezone()
122122
*
123123
* @return $this
124124
*/
125-
public function __setTimezone($timezone = null)
125+
public function setTimezone($timezone = null)
126126
{
127127
$clone = $this->clone();
128128

@@ -138,7 +138,7 @@ public function __setTimezone($timezone = null)
138138
*
139139
* @return $this
140140
*/
141-
public function __setDate($date = null)
141+
public function setDate($date = null)
142142
{
143143
$clone = $this->clone();
144144
$clone->date = TimeHelper::setPassedDate($date);
@@ -176,7 +176,7 @@ private function setTimeZoneAndTimeStamp($timezone = null)
176176
private function timestampPrint()
177177
{
178178
// ensure timezone cached
179-
$this->timezone = $this->getTimeZone();
179+
$this->timezone = $this->getTimezone();
180180
$this->timezoneName = $this->timezone;
181181

182182
// refresh system timezone and cache UTC offset
@@ -209,7 +209,7 @@ public function debugTimestamp(): string
209209
{
210210
$date = $this->format('Y-m-d H:i:s');
211211
$micro = $this->microseconds();
212-
$tz = (string) $this->__getTimezone();
212+
$tz = (string) $this->getTimezone();
213213
$offset = date('(P)', (int) $this->date);
214214
return sprintf('%s.%s %s %s', $date, $micro, $tz, $offset);
215215
}
@@ -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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
// $time4->year(),
3636
// ];
3737

38+
dd(
39+
$time2,
40+
$time3::greetings('24 Jan 2025 14:00:00'),
41+
);
42+
3843
dd(
3944
[
4045
'Time-1: '. $time->getTimeZone(),

0 commit comments

Comments
 (0)