From ddc71f86f62549c14d9d95892b2dc3df54cfd96e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 4 Jan 2017 15:10:21 +0100 Subject: [PATCH] Fixing January bug `smartModifz(-1)` in January would go back 2 years since `1-1+0 <= 0` resulting in `0 - 1` as `$y_change` --- Datatypes/SmartDateTime.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Datatypes/SmartDateTime.php b/Datatypes/SmartDateTime.php index bc89fdf9f..cdceca19b 100644 --- a/Datatypes/SmartDateTime.php +++ b/Datatypes/SmartDateTime.php @@ -90,8 +90,8 @@ class SmartDateTime extends \DateTime */ public function smartModify(int $y, int $m = 0, int $d = 0, int $calendar = CAL_GREGORIAN) : SmartDateTime { - $y_change = (int) floor(((int) $this->format('m') - 1 + $m) / 12); - $y_change = ((int) $this->format('m') - 1 + $m) <= 0 && ((int) $this->format('m') - 1 + $m) % 12 === 0 ? $y_change - 1 : $y_change; + $y_change = floor(((int) $this->format('m') - 1 + $m) / 12); + $y_change = ((int) $this->format('m') - 1 + $m) < 0 && ((int) $this->format('m') - 1 + $m) % 12 === 0 ? $y_change - 1 : $y_change; $y_new = (int) $this->format('Y') + $y + $y_change; $m_new = ((int) $this->format('m') + $m) % 12; $m_new = $m_new === 0 ? 12 : $m_new < 0 ? 12 + $m_new : $m_new;