diff --git a/README.md b/README.md index 5f6c8a8..6d5429b 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,10 @@ use \Verta as Verta ;` // default timestamp is now $dt = new Verta(); // OR -$dt = Verta::now(); +$dt = Verta::now(); +return Verta::today(); //1396-03-02 00:00:00 +return Verta::tomorrow(); // 1396-03-03 00:00:00 +return Verta::yesterday(); // 1396-03-01 00:00:00 // pass string datetime $dt = new Verta('2016-12-27 14:12:32'); @@ -100,6 +103,10 @@ return $dt->formatTime(); // 23:26:35 return $dt->formatJalaliDatetime(); // 1395/12/10 23:46:09 return $dt->formatJalaliDate(); // 1395/12/10 +// get gregorain datetime +return $dt->DateTime()->format('Y-m-d H:i:s'); // 2017-05-23 23:21:02 +return $dt->formatGregorian('Y-m-d H:i:s'); // 2017-05-23 23:21:02 + // set default format Verta::setStringformat('Y/n/j H:i:s'); return new Verta(); // 1395/12/12 00:11:35 diff --git a/src/Verta.php b/src/Verta.php index 4f96838..ac0acd3 100755 --- a/src/Verta.php +++ b/src/Verta.php @@ -401,6 +401,42 @@ class Verta extends DateTime { public static function now() { return new static(); } + /** + * Create a Carbon instance for today. + * + * @param \DateTimeZone|string|null $tz + * + * @return static + */ + + public static function today($tz = null) + { + return static::now($tz)->startOfDay(); + } + + /** + * Create a Carbon instance for tomorrow. + * + * @param \DateTimeZone|string|null $tz + * + * @return static + */ + public static function tomorrow($tz = null) + { + return static::today($tz)->addDay(); + } + + /** + * Create a Carbon instance for yesterday. + * + * @param \DateTimeZone|string|null $tz + * + * @return static + */ + public static function yesterday($tz = null) + { + return static::today($tz)->subDay(); + } /** * Create a Verta instance from a DateTime one @@ -969,6 +1005,17 @@ class Verta extends DateTime { return $this->strftime($format); } + /** + * The format of the outputted date string (gregorian) + * + * @param $format + * @return string + */ + public function formatGregorian($format) { + + return $this->DateTime()->format($format); + } + /** * Format the instance as date * @@ -1485,7 +1532,29 @@ class Verta extends DateTime { return $this->addSeconds(-1 * $value); } - /***************************** CONVERTION ****************************/ + /***************************** MODIFY ****************************/ + + /** + * Resets the time to 00:00:00 + * + * @return static + */ + public function startOfDay() + { + return $this->setTime(0, 0, 0); + } + + /** + * Resets the time to 23:59:59 + * + * @return static + */ + public function endOfDay() + { + return $this->setTime(23, 59, 59); + } + + /***************************** CONVERT ****************************/ /** * gregorian to jalali convertion