fix test last month
This commit is contained in:
1 parent
40e00c1fa2
commit
84a873f345
6 files changed
+19
-30
No files matched your search
@@ -395,7 +395,7 @@ trait Comparison
|
||||
*/
|
||||
public function isNextMonth()
|
||||
{
|
||||
return $this->month === static::now($this->getTimezone())->addMonth()->month;
|
||||
return $this->format('Y-m') === static::now($this->getTimezone())->addMonth()->format('Y-m');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -405,7 +405,7 @@ trait Comparison
|
||||
*/
|
||||
public function isLastMonth()
|
||||
{
|
||||
return $this->month === static::now($this->getTimezone())->subMonth()->month;
|
||||
return $this->format('Y-m') === static::now($this->getTimezone())->subMonth()->format('Y-m');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -458,7 +458,7 @@ trait Comparison
|
||||
*/
|
||||
public function isSameAs($format, Verta $v = null)
|
||||
{
|
||||
$v = $v ?: static::now($this->timezone);
|
||||
$v = $v ?: static::now($this->getTimezone());
|
||||
|
||||
return $this->format($format) === $v->format($format);
|
||||
}
|
||||
|
||||
@@ -12,16 +12,14 @@ trait Creator
|
||||
/**
|
||||
* create object of Jalali
|
||||
*
|
||||
* @param null $datetime
|
||||
* @param bool $timezone [optional]
|
||||
* @param DateTime|string|int|null $datetime [optional]
|
||||
* @param DateTimeZone|string|null $timezone [optional]
|
||||
* @internal param timestamp $timestamp [optional]
|
||||
*/
|
||||
public function __construct($datetime = null, $timezone = null)
|
||||
{
|
||||
$dt = $datetime;
|
||||
if (static::$testNow) {
|
||||
$dt = static::$testNow;
|
||||
} elseif (empty($datetime)) {
|
||||
if (empty($datetime)) {
|
||||
$dt = 'now';
|
||||
} elseif (is_string($datetime)) {
|
||||
$dt = self::faToEnNumbers(self::arToEnNumbers($datetime));
|
||||
@@ -254,7 +252,7 @@ trait Creator
|
||||
|
||||
/**
|
||||
* @param null $timezone
|
||||
* @return DateTimeZone|null
|
||||
* @return DateTimeZone|string|null
|
||||
*/
|
||||
protected static function createTimeZone($timezone = null)
|
||||
{
|
||||
|
||||
+9
-17
@@ -6,23 +6,15 @@ use Hekmatinasser\Verta\VertaInterface;
|
||||
|
||||
trait Date
|
||||
{
|
||||
use Accessor;
|
||||
use Comparison;
|
||||
use Creator;
|
||||
use Formatting;
|
||||
use Modification;
|
||||
use Transformation;
|
||||
use Translator;
|
||||
use Boundaries;
|
||||
use Difference;
|
||||
|
||||
/**
|
||||
* Format to use for __toString.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $testNow = null;
|
||||
|
||||
use Accessor,
|
||||
Comparison,
|
||||
Creator,
|
||||
Formatting,
|
||||
Modification,
|
||||
Transformation,
|
||||
Translator,
|
||||
Boundaries,
|
||||
Difference;
|
||||
/**
|
||||
* Format to use for __toString.
|
||||
*
|
||||
|
||||
@@ -249,7 +249,7 @@ class ComparisionTest extends TestCase
|
||||
$datetime = Verta::parse('1397-10-10 21:30:50');
|
||||
$target = Verta::parse('1398-10-10 21:30:01');
|
||||
|
||||
Verta::$testNow = $datetime->formatGregorian('Y-m-d H:i:s');
|
||||
// Verta::setTestNow('1397-10-10 21:30:50');
|
||||
|
||||
$this->assertTrue($datetime->isWeekday());
|
||||
$this->assertFalse($datetime->isWeekend());
|
||||
@@ -264,7 +264,6 @@ class ComparisionTest extends TestCase
|
||||
$this->assertFalse($datetime->isLastYear());
|
||||
$this->assertFalse($datetime->isFuture());
|
||||
$this->assertTrue($datetime->isPast());
|
||||
|
||||
$this->assertTrue($datetime->isSameAs('m-d', $target));
|
||||
$this->assertFalse($datetime->isSameAs('Y-m-d'));
|
||||
$this->assertFalse($datetime->isCurrentYear());
|
||||
@@ -279,6 +278,5 @@ class ComparisionTest extends TestCase
|
||||
$this->assertFalse($datetime->isThursday());
|
||||
$this->assertFalse($datetime->isFriday());
|
||||
|
||||
Verta::$testNow = null;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CreatorTest extends TestCase
|
||||
{
|
||||
|
||||
public function testNow()
|
||||
{
|
||||
$expected = (new DateTime())->getTimestamp();
|
||||
|
||||
@@ -216,7 +216,7 @@ class ModificationTest extends TestCase
|
||||
|
||||
public function testEndYear()
|
||||
{
|
||||
$datetime = Verta::parse('1398-10-10 21:30:20');
|
||||
$datetime = Verta::parse('1398-10-15 21:30:20');
|
||||
|
||||
$result = $datetime->endYear()->format('Y-m-d H:i:s');
|
||||
|
||||
|
||||
Reference in new issue
Block a user