fix strict type set date

This commit is contained in:
nasser committed 2022-02-18 13:12:18 +03:30
1 parent e0b5628976
commit 8ecabc5a5e
5 files changed
+14 -12

No files matched your search

+2 -2
View File
@@ -212,7 +212,7 @@ $v = $v->timezone('Asia/Baku');
<pre> <pre>
$v = $v->setDateTime(1395, 4, 25, 16, 50, 42); $v = $v->setDateTime(1395, 4, 25, 16, 50, 42);
$v = $v->setDateTime(1395, 4, 25, 16, 50, 42, 1569856); $v = $v->setDateTime(1395, 4, 25, 16, 50, 42, 1569856);
$v = $v->setDate(1395, 4, 25); $v = $v->setDateJalali(1395, 4, 25);
$v = $v->setTimeString('12:25:48'); $v = $v->setTimeString('12:25:48');
</pre> </pre>
<h2 id="format">Format</h2> <h2 id="format">Format</h2>
@@ -365,7 +365,7 @@ return $v1->gt($v2); // true alias greaterThan()
return $v1->gte($v2); // true alias greaterThanOrEqualTo() return $v1->gte($v2); // true alias greaterThanOrEqualTo()
return $v1->lt($v2); // false alias lessThan() return $v1->lt($v2); // false alias lessThan()
return $v1->lte($v2); // false alias lessThanOrEqualTo() return $v1->lte($v2); // false alias lessThanOrEqualTo()
return $v1->between($v2, $v3); // false return $v1->between($v2, $v3); // false
</pre> </pre>
<p>To compere datetime for closest, farthest, min or max together, use the following command</p> <p>To compere datetime for closest, farthest, min or max together, use the following command</p>
<pre> <pre>
+1 -1
View File
@@ -217,7 +217,7 @@ $v = $v->timezone('Asia/Baku');
<pre> <pre>
$v = $v->setDateTime(1395, 4, 25, 16, 50, 42); $v = $v->setDateTime(1395, 4, 25, 16, 50, 42);
$v = $v->setDateTime(1395, 4, 25, 16, 50, 42, 1569856); $v = $v->setDateTime(1395, 4, 25, 16, 50, 42, 1569856);
$v = $v->setDate(1395, 4, 25); $v = $v->setDateJalali(1395, 4, 25);
$v = $v->setTimeString('12:25:48'); $v = $v->setTimeString('12:25:48');
</pre> </pre>
<h2 id="format">قالب نمایش</h2> <h2 id="format">قالب نمایش</h2>
+8 -6
View File
@@ -229,7 +229,7 @@ trait Accessor
*/ */
public function setDateTime($year, $month, $day, $hour, $minute, $second = 0, $microseconds = 0) public function setDateTime($year, $month, $day, $hour, $minute, $second = 0, $microseconds = 0)
{ {
return $this->setDate($year, $month, $day)->setTime($hour, $minute, $second, $microseconds); return $this->setDateJalali($year, $month, $day)->setTime($hour, $minute, $second, $microseconds);
} }
/** /**
@@ -242,12 +242,13 @@ trait Accessor
* *
* @return Verta * @return Verta
*/ */
public function setDate($year, $month, $day) public function setDateJalali($year, $month, $day)
{ {
list($year, $month, $day) = self::getGregorian($year, $month, $day); list($year, $month, $day) = self::getGregorian($year, $month, $day);
parent::setDate($year, $month, $day); if(static::isValidDate($year, $month, $day)) {
parent::setDate($year, $month, $day);
}
return $this; return $this;
} }
@@ -268,8 +269,9 @@ trait Accessor
$minute = $time[1] ?? 0; $minute = $time[1] ?? 0;
$second = $time[2] ?? 0; $second = $time[2] ?? 0;
parent::setTime($hour, $minute, $second, 0); if(static::isValidTime($hour, $minute, $second)) {
parent::setTime($hour, $minute, $second, 0);
}
return $this; return $this;
} }
} }
+1 -1
View File
@@ -133,7 +133,7 @@ trait Boundaries
{ {
$month = $this->quarter * static::MONTHS_PER_QUARTER; $month = $this->quarter * static::MONTHS_PER_QUARTER;
return $this->setDate($this->year, $month, 1)->endMonth(); return $this->setDateJalali($this->year, $month, 1)->endMonth();
} }
/** /**
+2 -2
View File
@@ -97,9 +97,9 @@ class AccessTest extends TestCase
$this->assertEquals(11, $datetime->second); $this->assertEquals(11, $datetime->second);
} }
public function testSetDate() public function testSetDateJalali()
{ {
$datetime = verta()->setDate(1397, 10, 11); $datetime = verta()->setDateJalali(1397, 10, 11);
$this->assertEquals(1397, $datetime->year); $this->assertEquals(1397, $datetime->year);
$this->assertEquals(10, $datetime->month); $this->assertEquals(10, $datetime->month);