Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
hekmatinasser committed Nov 13, 2020
1 parent 48f0d68 commit fe687e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/Traits/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Hekmatinasser\Verta\Traits;

use DateTime;
use DateTimeInterface;
use DateTimeZone;
use Exception;
use InvalidArgumentException;
Expand Down Expand Up @@ -62,7 +61,7 @@ public static function now($timezone = null) {

public static function today($timezone = null)
{
return static::now($timezone)->startDay();
return (new static($timezone))->startDay();
}

/**
Expand All @@ -74,7 +73,7 @@ public static function today($timezone = null)
*/
public static function tomorrow($timezone = null)
{
return static::today($timezone)->addDay();
return (new static('+1 day', $timezone))->startDay();
}

/**
Expand All @@ -86,7 +85,7 @@ public static function tomorrow($timezone = null)
*/
public static function yesterday($timezone = null)
{
return static::today($timezone)->subDay();
return (new static('-1 day', $timezone))->startDay();
}

/**
Expand Down
17 changes: 7 additions & 10 deletions src/Traits/Formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function date($format){
$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 );

Expand Down Expand Up @@ -205,7 +205,7 @@ protected function dateWord($format){

$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);

Expand Down Expand Up @@ -300,14 +300,10 @@ protected function dateWord($format){

# 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':
Expand All @@ -316,15 +312,15 @@ protected function dateWord($format){
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':
case 'O':
case 'P':
case 'T':
case 'Z':
$result .= date($par, $timestamp);
$result .= parent::format($par);
break;

# Full Date/Time
Expand Down Expand Up @@ -481,6 +477,7 @@ public function format($format) {
public function formatGregorian($format) {

return $this->datetime()->format($format);
return $this->datetime()->format($format);
}

/**
Expand Down

2 comments on commit fe687e2

@javadzanguei
Copy link

@javadzanguei javadzanguei commented on fe687e2 Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two return lines ?!!!

public function formatGregorian($format) {
        return $this->datetime()->format($format);
        return $this->datetime()->format($format);
}

@hekmatinasser
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok tnx

Please sign in to comment.