@@ -254,25 +254,6 @@ public function subYears($value = 0)
254254 {
255255 return $ this ->buildTimeModifier ('year ' , $ value , true );
256256 }
257-
258- /**
259- * Create timestamp
260- *
261- * @param int|string $date
262- * - string|int|float
263- *
264- * @param string $format
265- * - Your defined format type i.e: Y-m-d H:i:s a
266- * - Converted TimeStamp
267- *
268- * @return string
269- */
270- public static function timestamp ($ date , $ format = "Y-m-d H:i:s " )
271- {
272- $ date = TimeHelper::setPassedDate ($ date );
273-
274- return date ($ format , $ date );
275- }
276257
277258 /**
278259 * Set custom time
@@ -286,20 +267,6 @@ public static function date($date)
286267 return $ base ->setDate ($ date );
287268 }
288269
289- /**
290- * Create date from Format
291- *
292- * @param int|string $datetime
293- * @param string $format
294- * @return $this
295- */
296- public static function createFromFormat ($ datetime , $ format = 'm/d/Y h:i:sa ' )
297- {
298- return self ::date (
299- self ::timestamp ($ datetime , $ format )
300- );
301- }
302-
303270 /**
304271 * Format a date range.
305272 *
@@ -360,6 +327,52 @@ public static function yesterday()
360327 return self ::date ('yesterday ' );
361328 }
362329
330+ /**
331+ * Create timestamp
332+ *
333+ * @param int|string $date
334+ * - string|int
335+ *
336+ * @param string $format
337+ * - Your defined format type i.e: Y-m-d H:i:s a
338+ * - Converted TimeStamp
339+ *
340+ * @return string
341+ */
342+ public static function timestamp ($ date , $ format = "Y-m-d H:i:s " )
343+ {
344+ $ date = TimeHelper::setPassedDate ($ date );
345+
346+ return date ($ format , $ date );
347+ }
348+
349+ /**
350+ * Create date from Format
351+ *
352+ * @param string $format
353+ * @param int|string|null $datetime
354+ * @return string
355+ */
356+ public static function createFromFormat ($ format = 'Y-m-d H:i:s.u ' , $ datetime = null )
357+ {
358+ return self ::date (
359+ self ::timestamp ($ datetime ?: 'now ' )
360+ )->format ($ format );
361+ }
362+
363+ /**
364+ * Create date from date string
365+ *
366+ * @param int|string $datetime
367+ * @return string
368+ */
369+ public static function createFromDateString ($ datetime )
370+ {
371+ return self ::date (
372+ self ::timestamp ($ datetime )
373+ )->format ('Y-m-d H:i:s.u ' );
374+ }
375+
363376 /**
364377 * Format time input
365378 *
@@ -374,8 +387,7 @@ public static function yesterday()
374387 public function format ($ format = null , $ date = null )
375388 {
376389 if (!empty ($ date )) {
377- $ clone = self ::date ($ date );
378- $ this ->date = $ clone ->date ;
390+ $ this ->date = TimeHelper::setPassedDate ($ date );
379391 }
380392
381393 if (empty ($ format )){
@@ -395,6 +407,26 @@ public function toDateTimeString()
395407 return $ this ->format ();
396408 }
397409
410+ /**
411+ * toDateString
412+ *
413+ * @return string
414+ */
415+ public function toDateString ()
416+ {
417+ return $ this ->format ('Y-m-d ' );
418+ }
419+
420+ /**
421+ * toTimeString
422+ *
423+ * @return string
424+ */
425+ public function toTimeString ()
426+ {
427+ return $ this ->format ('H:i:s ' );
428+ }
429+
398430 /**
399431 * Create Javascript timer
400432 *
@@ -445,70 +477,70 @@ public static function config(?array $options = [])
445477 * Get the stored date time
446478 * @return int
447479 */
448- public function __getDate ()
480+ public function __date ()
449481 {
450482 return (int ) $ this ->date ;
451483 }
452484
453485 /**
454486 * Get the number of seconds between the stored time and the current time.
455- * @return mixed
487+ * @return int
456488 */
457- public function __getSecond ()
489+ public function __second ()
458490 {
459491 return $ this ->__timeDifference ('sec ' );
460492 }
461493
462494 /**
463495 * Get the number of minutes between the stored time and the current time.
464- * @return mixed
496+ * @return int
465497 */
466- public function __getMin ()
498+ public function __min ()
467499 {
468500 return $ this ->__timeDifference ('mins ' );
469501 }
470502
471503 /**
472504 * Get the number of hours between the stored time and the current time.
473- * @return mixed
505+ * @return int
474506 */
475- public function __getHour ()
507+ public function __hour ()
476508 {
477509 return $ this ->__timeDifference ('hour ' );
478510 }
479511
480512 /**
481513 * Get the number of days between the stored time and the current time.
482- * @return mixed
514+ * @return int
483515 */
484- public function __getDay ()
516+ public function __day ()
485517 {
486518 return $ this ->__timeDifference ('days ' );
487519 }
488520
489521 /**
490522 * Get the number of weeks between the stored time and the current time.
491- * @return mixed
523+ * @return int
492524 */
493- public function __getWeek ()
525+ public function __week ()
494526 {
495527 return $ this ->__timeDifference ('weeks ' );
496528 }
497529
498530 /**
499531 * Get the number of months between the stored time and the current time.
500- * @return mixed
532+ * @return int
501533 */
502- public function __getMonth ()
534+ public function __month ()
503535 {
504536 return $ this ->__timeDifference ('month ' );
505537 }
506538
507539 /**
508540 * Get the number of years between the stored time and the current time.
509- * @return mixed
541+ * @return int
510542 */
511- public function __getYear ()
543+ public function __year ()
512544 {
513545 return $ this ->__timeDifference ('year ' );
514546 }
@@ -609,7 +641,7 @@ public function __timeAgo($mode = null)
609641 $ days = $ diff ['days ' ];
610642 $ weeks = $ diff ['weeks ' ];
611643 $ years = $ diff ['year ' ];
612- $ date = $ this ->__getDate ();
644+ $ date = $ this ->__date ();
613645 $ text = self ::getText ();
614646
615647 if ($ days === 0 && $ hours === 0 && $ minutes < 1 ) {
@@ -667,12 +699,6 @@ public function __timeAgo($mode = null)
667699 return $ data [$ mode ] ?? $ data ;
668700 }
669701
670- /**
671- * Get the text representation options.
672- * @param string|null $mode
673- *
674- * @return mixed
675- */
676702 /**
677703 * Retrieve text configuration entries.
678704 *
@@ -706,12 +732,15 @@ public function __debugInfo(): array
706732 $ time = (int ) $ this ->date ;
707733
708734 return [
709- 'timestamp ' => $ time ,
735+ 'date ' => $ time ,
736+ 'timestamp ' => $ this ->timestamp ,
710737 'formatted ' => date ('Y-m-d H:i:s ' , $ time ),
711738 'timezone ' => (string ) ($ this ->timezoneName ?? $ this ->timezone ),
712739 'utc_offset ' => ($ this ->utcOffset ?? date ('(P) ' , $ time )),
713740 'greeting ' => $ this ->__greeting ($ time ),
714741 'time_ago_short ' => $ this ->__timeAgo ('short ' ),
742+ 'time_ago ' => $ this ->__timeAgo (),
743+ 'time_diff ' => $ this ->__timeDifference (),
715744 ];
716745 }
717746}
0 commit comments