From fe687e25e3ab26b43d95b25ef7dc591ce28184d7 Mon Sep 17 00:00:00 2001 From: Nasser Date: Fri, 13 Nov 2020 22:32:37 +0330 Subject: [PATCH] fix format --- src/Traits/Creator.php | 7 +++---- src/Traits/Formatting.php | 17 +++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Traits/Creator.php b/src/Traits/Creator.php index e95f1f8..436fb73 100644 --- a/src/Traits/Creator.php +++ b/src/Traits/Creator.php @@ -4,7 +4,6 @@ namespace Hekmatinasser\Verta\Traits; use DateTime; -use DateTimeInterface; use DateTimeZone; use Exception; use InvalidArgumentException; @@ -62,7 +61,7 @@ trait Creator public static function today($timezone = null) { - return static::now($timezone)->startDay(); + return (new static($timezone))->startDay(); } /** @@ -74,7 +73,7 @@ trait Creator */ public static function tomorrow($timezone = null) { - return static::today($timezone)->addDay(); + return (new static('+1 day', $timezone))->startDay(); } /** @@ -86,7 +85,7 @@ trait Creator */ public static function yesterday($timezone = null) { - return static::today($timezone)->subDay(); + return (new static('-1 day', $timezone))->startDay(); } /** diff --git a/src/Traits/Formatting.php b/src/Traits/Formatting.php index ecf94f4..816c880 100644 --- a/src/Traits/Formatting.php +++ b/src/Traits/Formatting.php @@ -48,7 +48,7 @@ trait Formatting $timestamp = $this->getTimestamp(); - list( $gYear, $gMonth, $gDay, $gWeek ) = explode( '-', date('Y-m-d-w', $timestamp) ); + list( $gYear, $gMonth, $gDay, $gWeek ) = explode( '-', parent::format('Y-m-d-w')); list( $pYear, $pMonth, $pDay ) = static::getJalali( $gYear, $gMonth, $gDay ); $pWeek = ( $gWeek + 1 ); @@ -205,7 +205,7 @@ trait Formatting $timestamp = $this->getTimestamp(); - list($gYear, $gMonth, $gDay, $gWeek) = explode('-', date('Y-m-d-w', $timestamp)); + list($gYear, $gMonth, $gDay, $gWeek) = explode('-', parent::format('Y-m-d-w')); list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay); $pWeek = ($gWeek + 1); @@ -300,14 +300,10 @@ trait Formatting # Time case 'a': + $result .= (parent::format('a') == 'am' ? self::AM : self::PM); case 'A': - if (date('a', $timestamp) == 'am') { - $result .= (($par == 'a') ? self::AM : self::ANTE_MERIDIEM); - } else { - $result .= (($par == 'a') ? self::PM : self::POST_MERIDIEM); - } + $result .= (parent::format('a') == 'am' ? self::ANTE_MERIDIEM : self::POST_MERIDIEM); break; - case 'B': case 'g': case 'G': @@ -316,7 +312,7 @@ trait Formatting case 's': case 'u': case 'i': - $result .= $word->getWord(strval(date($par, $timestamp))); + $result .= $word->getWord(strval(parent::format($par))); break; case 'e': case 'I': @@ -324,7 +320,7 @@ trait Formatting case 'P': case 'T': case 'Z': - $result .= date($par, $timestamp); + $result .= parent::format($par); break; # Full Date/Time @@ -481,6 +477,7 @@ trait Formatting public function formatGregorian($format) { return $this->datetime()->format($format); + return $this->datetime()->format($format); } /**