From eea78fe25a44487fda20fddfb199565f038616d4 Mon Sep 17 00:00:00 2001 From: Nasser Hekmati Date: Tue, 2 May 2017 23:15:08 +0430 Subject: [PATCH] add calculation year --- src/Verta.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/Verta.php b/src/Verta.php index 5fdf8dc..c4f510c 100755 --- a/src/Verta.php +++ b/src/Verta.php @@ -888,8 +888,62 @@ class Verta extends DateTime { && $second >= 0 && $second <= 59; } - - /***************************** CONVERTION ****************************/ + + /***************************** CALCULATION ****************************/ + + /** + * Add years to the instance. Positive $value travel forward while + * negative $value travel into the past. + * + * @param int $value + * + * @return static + */ + public function addYears($value) + { + return $this->modify((int) $value.' year'); + } + + /** + * Add a year to the instance + * + * @param int $value + * + * @return static + */ + public function addYear($value = 1) + { + return $this->addYears($value); + } + + /** + * Remove years from the instance. + * + * @param int $value + * + * @return static + */ + public function subYears($value) + { + return $this->addYears(-1 * $value)->modify('-1 day'); + } + + /** + * Remove a year from the instance + * + * @param int $value + * + * @return static + */ + public function subYear($value = 1) + { + return $this->subYears($value); + } + + + + + /***************************** CONVERTION ****************************/ /** * gregorian to jalali convertion