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( ), timeAgo( )
2323 *
2424 * All methods are documented at their definitions for clarity.
2525 */
@@ -82,25 +82,17 @@ public function __construct($date = null, $timezone = null)
8282 }
8383
8484 if (empty ($ this ->date )) {
85- $ clone = $ this ->setDate ($ date );
85+ $ date = $ date ?: 'now ' ;
86+ $ clone = self ::date ($ date );
8687
8788 $ this ->date = $ clone ->date ;
8889 $ this ->timestamp = $ clone ->timestamp ;
8990 $ this ->timezone = $ clone ->timezone ;
9091 }
91-
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 ();
92+
93+ $ this ->keepStaticBinding ($ this ->clone ());
9594 }
9695
97- /**
98- * Handle the calls to non-existent instance methods.
99- * @param string $name
100- * @param mixed $args
101- *
102- * @return mixed
103- */
10496 /**
10597 * Magic: instance dynamic calls map to supported methods.
10698 *
@@ -122,14 +114,11 @@ public function __call($name, $args)
122114 */
123115 public static function __callStatic ($ name , $ args )
124116 {
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 );
117+ return self ::nonExistMethod ($ name , $ args , self ::$ staticData );
131118 }
132119
120+
121+
133122 /**
134123 * Add Second to curent date
135124 * @param int $value
@@ -275,59 +264,80 @@ public function subYears($value = 0)
275264 {
276265 return $ this ->buildTimeModifier ('year ' , $ value , true );
277266 }
267+
268+ /**
269+ * Create timestamp
270+ *
271+ * @param int|string $date
272+ * - string|int|float
273+ *
274+ * @param string $format
275+ * - Your defined format type i.e: Y-m-d H:i:s a
276+ * - Converted TimeStamp
277+ *
278+ * @return string
279+ */
280+ public static function timestamp ($ date , $ format = "Y-m-d H:i:s " )
281+ {
282+ $ date = TimeHelper::setPassedDate ($ date );
283+
284+ return date ($ format , $ date );
285+ }
278286
279287 /**
280- * Create date from Format
281- *
282- * @param int|string $datetime
283- * @param string $format
288+ * Set custom time
289+ * @param int|string $date
284290 * @return $this
285291 */
286- public function createFromFormat ( $ datetime , $ format = ' m/d/Y h:i:sa ' )
292+ public static function date ( $ date )
287293 {
288- return $ this -> setDate (
289- self :: timestamp ( $ datetime , $ format )
290- );
294+ $ base = self :: baseInstance ();
295+
296+ return $ base -> setDate ( $ date );
291297 }
292298
293299 /**
294- * Set custom time
295- * @param int|string $date
300+ * Create date from Format
301+ *
302+ * @param int|string $datetime
303+ * @param string $format
296304 * @return $this
297305 */
298- public function date ( $ date )
306+ public static function createFromFormat ( $ datetime , $ format = ' m/d/Y h:i:sa ' )
299307 {
300- return $ this ->setDate ($ date );
308+ return self ::date (
309+ self ::timestamp ($ datetime , $ format )
310+ );
301311 }
302312
303313 /**
304314 * Set time to `now`
305315 *
306316 * @return $this
307317 */
308- public function now ()
318+ public static function now ()
309319 {
310- return $ this -> date ('now ' );
320+ return self :: date ('now ' );
311321 }
312322
313323 /**
314324 * Set time to `today`
315325 *
316326 * @return $this
317327 */
318- public function today ()
328+ public static function today ()
319329 {
320- return $ this -> setDate ('today ' );
330+ return self :: date ('today ' );
321331 }
322332
323333 /**
324334 * Set time to `yesterday`
325335 *
326336 * @return $this
327337 */
328- public function yesterday ()
338+ public static function yesterday ()
329339 {
330- return $ this -> setDate ('yesterday ' );
340+ return self :: date ('yesterday ' );
331341 }
332342
333343 /**
@@ -344,7 +354,7 @@ public function yesterday()
344354 public function format ($ format = null , $ date = null )
345355 {
346356 if (!empty ($ date )) {
347- $ clone = $ this -> setDate ($ date );
357+ $ clone = self :: date ($ date );
348358 $ this ->date = $ clone ->date ;
349359 }
350360
@@ -365,25 +375,6 @@ public function toDateTimeString()
365375 return $ this ->format ();
366376 }
367377
368- /**
369- * Create timestamp
370- *
371- * @param int|string $date
372- * - string|int|float
373- *
374- * @param string $format
375- * - Your defined format type i.e: Y-m-d H:i:s a
376- * - Converted TimeStamp
377- *
378- * @return string
379- */
380- public static function timestamp ($ date , $ format = "Y-m-d H:i:s " )
381- {
382- $ date = TimeHelper::setPassedDate ($ date );
383-
384- return date ($ format , $ date );
385- }
386-
387378 /**
388379 * Create Javascript timer
389380 *
0 commit comments