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()
|
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()
|
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)
|
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);
|
return $this->format($format) === $v->format($format);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,16 +12,14 @@ trait Creator
|
|||||||
/**
|
/**
|
||||||
* create object of Jalali
|
* create object of Jalali
|
||||||
*
|
*
|
||||||
* @param null $datetime
|
* @param DateTime|string|int|null $datetime [optional]
|
||||||
* @param bool $timezone [optional]
|
* @param DateTimeZone|string|null $timezone [optional]
|
||||||
* @internal param timestamp $timestamp [optional]
|
* @internal param timestamp $timestamp [optional]
|
||||||
*/
|
*/
|
||||||
public function __construct($datetime = null, $timezone = null)
|
public function __construct($datetime = null, $timezone = null)
|
||||||
{
|
{
|
||||||
$dt = $datetime;
|
$dt = $datetime;
|
||||||
if (static::$testNow) {
|
if (empty($datetime)) {
|
||||||
$dt = static::$testNow;
|
|
||||||
} elseif (empty($datetime)) {
|
|
||||||
$dt = 'now';
|
$dt = 'now';
|
||||||
} elseif (is_string($datetime)) {
|
} elseif (is_string($datetime)) {
|
||||||
$dt = self::faToEnNumbers(self::arToEnNumbers($datetime));
|
$dt = self::faToEnNumbers(self::arToEnNumbers($datetime));
|
||||||
@@ -254,7 +252,7 @@ trait Creator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param null $timezone
|
* @param null $timezone
|
||||||
* @return DateTimeZone|null
|
* @return DateTimeZone|string|null
|
||||||
*/
|
*/
|
||||||
protected static function createTimeZone($timezone = null)
|
protected static function createTimeZone($timezone = null)
|
||||||
{
|
{
|
||||||
|
|||||||
+9
-17
@@ -6,23 +6,15 @@ use Hekmatinasser\Verta\VertaInterface;
|
|||||||
|
|
||||||
trait Date
|
trait Date
|
||||||
{
|
{
|
||||||
use Accessor;
|
use Accessor,
|
||||||
use Comparison;
|
Comparison,
|
||||||
use Creator;
|
Creator,
|
||||||
use Formatting;
|
Formatting,
|
||||||
use Modification;
|
Modification,
|
||||||
use Transformation;
|
Transformation,
|
||||||
use Translator;
|
Translator,
|
||||||
use Boundaries;
|
Boundaries,
|
||||||
use Difference;
|
Difference;
|
||||||
|
|
||||||
/**
|
|
||||||
* Format to use for __toString.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public static $testNow = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format to use for __toString.
|
* Format to use for __toString.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ class ComparisionTest extends TestCase
|
|||||||
$datetime = Verta::parse('1397-10-10 21:30:50');
|
$datetime = Verta::parse('1397-10-10 21:30:50');
|
||||||
$target = Verta::parse('1398-10-10 21:30:01');
|
$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->assertTrue($datetime->isWeekday());
|
||||||
$this->assertFalse($datetime->isWeekend());
|
$this->assertFalse($datetime->isWeekend());
|
||||||
@@ -264,7 +264,6 @@ class ComparisionTest extends TestCase
|
|||||||
$this->assertFalse($datetime->isLastYear());
|
$this->assertFalse($datetime->isLastYear());
|
||||||
$this->assertFalse($datetime->isFuture());
|
$this->assertFalse($datetime->isFuture());
|
||||||
$this->assertTrue($datetime->isPast());
|
$this->assertTrue($datetime->isPast());
|
||||||
|
|
||||||
$this->assertTrue($datetime->isSameAs('m-d', $target));
|
$this->assertTrue($datetime->isSameAs('m-d', $target));
|
||||||
$this->assertFalse($datetime->isSameAs('Y-m-d'));
|
$this->assertFalse($datetime->isSameAs('Y-m-d'));
|
||||||
$this->assertFalse($datetime->isCurrentYear());
|
$this->assertFalse($datetime->isCurrentYear());
|
||||||
@@ -279,6 +278,5 @@ class ComparisionTest extends TestCase
|
|||||||
$this->assertFalse($datetime->isThursday());
|
$this->assertFalse($datetime->isThursday());
|
||||||
$this->assertFalse($datetime->isFriday());
|
$this->assertFalse($datetime->isFriday());
|
||||||
|
|
||||||
Verta::$testNow = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
class CreatorTest extends TestCase
|
class CreatorTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testNow()
|
public function testNow()
|
||||||
{
|
{
|
||||||
$expected = (new DateTime())->getTimestamp();
|
$expected = (new DateTime())->getTimestamp();
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ class ModificationTest extends TestCase
|
|||||||
|
|
||||||
public function testEndYear()
|
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');
|
$result = $datetime->endYear()->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user