add today, tomorrow, yesterday
This commit is contained in:
1 parent
8ba7ebe7ca
commit
d9b5296346
2 files changed
+77
-1
No files matched your search
@@ -42,6 +42,9 @@ use \Verta as Verta ;`
|
||||
$dt = new Verta();
|
||||
// OR
|
||||
$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
|
||||
|
||||
+70
-1
@@ -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
|
||||
|
||||
Reference in new issue
Block a user