1010use Tamedevelopers \Support \Traits \TimeTrait ;
1111use Tamedevelopers \Support \Capsule \TimeHelper ;
1212
13+ /**
14+ * Class Time
15+ *
16+ * Time utility with dynamic static/instance method support.
17+ * - Supports setters like date(), now(), today(), yesterday()
18+ * - Add/subtract helpers: addSeconds/Minutes/Hours/Days/Weeks/Months/Years and sub*
19+ * - Formatting: format(), toDateTimeString(), toJsTimer(), timestamp()
20+ * - Range helper: dateRange()
21+ * - Text features/config: config(), greeting (via __greeting), timeAgo (via __timeAgo)
22+ *
23+ * All methods are documented at their definitions for clarity.
24+ */
1325class Time {
1426
1527 use TimeTrait;
1628
1729 /**
18- * For storing the time value
19- *
20- * @var mixed
21- * - int|string
30+ * For storing the time value.
31+ *
32+ * @var int|string
2233 */
2334 protected $ date ;
2435
2536 /**
26- * For storing the timestamp value
27- *
37+ * For storing a human-friendly timestamp snapshot
38+ * (e.g., "2024-01-01 12:00:00.123456 UTC (+00:00)").
39+ *
2840 * @var string
2941 */
3042 protected $ timestamp ;
3143
3244 /**
33- * For storing the timezone value
34- *
45+ * For storing the timezone value.
46+ *
3547 * @var string
3648 */
3749 protected $ timezone ;
50+
51+ /**
52+ * Cached timezone name (alias of $timezone) for quick access.
53+ *
54+ * @var string|null
55+ */
56+ protected $ timezoneName ;
57+
58+ /**
59+ * Cached UTC offset for the current $date (e.g., "+00:00").
60+ *
61+ * @var string|null
62+ */
63+ protected $ utcOffset ;
3864
3965 /**
4066 * static
@@ -75,6 +101,13 @@ public function __construct($date = null, $timezone = null)
75101 *
76102 * @return mixed
77103 */
104+ /**
105+ * Magic: instance dynamic calls map to supported methods.
106+ *
107+ * @param string $name Invoked method name
108+ * @param array $args Arguments
109+ * @return mixed
110+ */
78111 public function __call ($ name , $ args )
79112 {
80113 return self ::nonExistMethod ($ name , $ args , $ this );
@@ -87,6 +120,13 @@ public function __call($name, $args)
87120 *
88121 * @return mixed
89122 */
123+ /**
124+ * Magic: static dynamic calls map to supported methods using stored static instance.
125+ *
126+ * @param string $name Invoked static method name
127+ * @param array $args Arguments
128+ * @return mixed
129+ */
90130 public static function __callStatic ($ name , $ args )
91131 {
92132 return self ::nonExistMethod ($ name , $ args , self ::$ staticData );
@@ -97,6 +137,12 @@ public static function __callStatic($name, $args)
97137 * @param int $value
98138 * @return $this
99139 */
140+ /**
141+ * Add seconds to the current date.
142+ *
143+ * @param int $value Number of seconds to add
144+ * @return $this New cloned instance with updated time
145+ */
100146 public function addSeconds ($ value = 0 )
101147 {
102148 return $ this ->buildTimeModifier ('second ' , $ value );
@@ -649,6 +695,12 @@ public function __timeAgo($mode = null)
649695 *
650696 * @return mixed
651697 */
698+ /**
699+ * Retrieve text configuration entries.
700+ *
701+ * @param string|null $mode Specific key to fetch or null for all
702+ * @return mixed
703+ */
652704 private static function getText ($ mode = null )
653705 {
654706 if (!defined ('TAME_TIME_CONFIG ' )){
@@ -657,5 +709,32 @@ private static function getText($mode = null)
657709
658710 return TAME_TIME_CONFIG [$ mode ] ?? TAME_TIME_CONFIG ;
659711 }
712+
713+ /**
714+ * Magic: customize what is displayed during var-dump/dd().
715+ * Provides a pretty, safe snapshot of the current time object.
716+ *
717+ * - timestamp: the unix timestamp (int)
718+ * - formatted: default formatted string (Y-m-d H:i:s)
719+ * - timezone: current timezone name
720+ * - utc_offset: offset at the timestamp time
721+ * - greeting: localized greeting based on hour
722+ * - time_ago_short: a compact time-ago string
723+ *
724+ * @return array
725+ */
726+ public function __debugInfo (): array
727+ {
728+ $ time = (int ) $ this ->date ;
729+
730+ return [
731+ 'timestamp ' => $ time ,
732+ 'formatted ' => date ('Y-m-d H:i:s ' , $ time ),
733+ 'timezone ' => (string ) $ this ->timezone ,
734+ 'utc_offset ' => date ('(P) ' , $ time ),
735+ 'greeting ' => $ this ->__greeting ($ time ),
736+ 'time_ago_short ' => $ this ->__timeAgo ('short ' ),
737+ ];
738+ }
660739}
661740
0 commit comments