fix set date
This commit is contained in:
1 parent
69a397ba33
commit
8ef16c1106
5 files changed
+24
-41
No files matched your search
+20
-37
@@ -13,12 +13,10 @@ trait Accessor
|
||||
* Get a part of the Verta object
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*
|
||||
* @return string|int|DateTimeZone
|
||||
* @return string|int
|
||||
*@throws InvalidArgumentException
|
||||
*/
|
||||
public function __get($name)
|
||||
public function __get(string $name)
|
||||
{
|
||||
static $formats = [
|
||||
'year' => 'Y',
|
||||
@@ -35,29 +33,25 @@ trait Accessor
|
||||
'timestamp' => 'U',
|
||||
];
|
||||
|
||||
switch (true) {
|
||||
case isset($formats[$name]):
|
||||
return (int) $this->format($formats[$name]);
|
||||
|
||||
case $name === 'quarter':
|
||||
return (int) ceil($this->month / static::MONTHS_PER_QUARTER);
|
||||
|
||||
case $name === 'timezone':
|
||||
return $this->getTimezone()->getName();
|
||||
|
||||
default:
|
||||
throw new InvalidArgumentException(sprintf("Unknown getter '%s'", $name));
|
||||
if(array_key_exists($name, $formats)) {
|
||||
return (int) $this->format($formats[$name]);
|
||||
}
|
||||
elseif ($name === 'quarter') {
|
||||
return (int) ceil($this->month / static::MONTHS_PER_QUARTER);
|
||||
}
|
||||
elseif ($name === 'timezone') {
|
||||
return $this->getTimezone()->getName();
|
||||
}
|
||||
throw new InvalidArgumentException(sprintf("Unknown getter '%s'", $name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an attribute exists on the object
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name)
|
||||
public function __isset(string $name)
|
||||
{
|
||||
try {
|
||||
$this->__get($name);
|
||||
@@ -71,12 +65,11 @@ trait Accessor
|
||||
/**
|
||||
* Set a part of the Verta object
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|int|\DateTimeZone $value
|
||||
*
|
||||
* @param string $name
|
||||
* @param \DateTimeZone|int|string $value
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
public function __set(string $name, DateTimeZone|int|string $value)
|
||||
{
|
||||
switch ($name) {
|
||||
case 'year':
|
||||
@@ -111,7 +104,6 @@ trait Accessor
|
||||
* Set the instance's year
|
||||
*
|
||||
* @param int $value
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function year($value)
|
||||
@@ -125,7 +117,6 @@ trait Accessor
|
||||
* Set the instance's month
|
||||
*
|
||||
* @param int $value
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function month($value)
|
||||
@@ -139,7 +130,6 @@ trait Accessor
|
||||
* Set the instance's day
|
||||
*
|
||||
* @param int $value
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function day($value)
|
||||
@@ -153,7 +143,6 @@ trait Accessor
|
||||
* Set the instance's hour
|
||||
*
|
||||
* @param int $value
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function hour($value)
|
||||
@@ -167,7 +156,6 @@ trait Accessor
|
||||
* Set the instance's minute
|
||||
*
|
||||
* @param int $value
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function minute($value)
|
||||
@@ -181,7 +169,6 @@ trait Accessor
|
||||
* Set the instance's second
|
||||
*
|
||||
* @param int $value
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function second($value)
|
||||
@@ -195,7 +182,6 @@ trait Accessor
|
||||
* Set the instance's timestamp
|
||||
*
|
||||
* @param int $value
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function timestamp($value)
|
||||
@@ -230,7 +216,7 @@ trait Accessor
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,8 +229,7 @@ trait Accessor
|
||||
*
|
||||
* @return Verta
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function setDate($year, $month, $day)
|
||||
public function setDateJalali(int $year, int $month, int $day): Verta
|
||||
{
|
||||
if (static::isValidDate($year, $month, $day)) {
|
||||
list($year, $month, $day) = self::getGregorian($year, $month, $day);
|
||||
@@ -258,12 +243,10 @@ trait Accessor
|
||||
* Set the time by time string
|
||||
*
|
||||
* @param string $time
|
||||
*
|
||||
* @return static
|
||||
*
|
||||
* @return Verta
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setTimeString($time)
|
||||
public function setTimeString(string $time): Verta
|
||||
{
|
||||
$time = explode(':', $time);
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ trait Boundaries
|
||||
{
|
||||
$month = $this->quarter * static::MONTHS_PER_QUARTER;
|
||||
|
||||
return $this->setDate($this->year, $month, 1)->endMonth();
|
||||
return $this->setDateJalali($this->year, $month, 1)->endMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user