add today, tomorrow, yesterday
This commit is contained in:
1 parent
8ba7ebe7ca
commit
d9b5296346
2 files changed
+78
-2
No files matched your search
@@ -41,7 +41,10 @@ use \Verta as Verta ;`
|
|||||||
// default timestamp is now
|
// default timestamp is now
|
||||||
$dt = new Verta();
|
$dt = new Verta();
|
||||||
// OR
|
// 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
|
// pass string datetime
|
||||||
$dt = new Verta('2016-12-27 14:12:32');
|
$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->formatJalaliDatetime(); // 1395/12/10 23:46:09
|
||||||
return $dt->formatJalaliDate(); // 1395/12/10
|
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
|
// set default format
|
||||||
Verta::setStringformat('Y/n/j H:i:s');
|
Verta::setStringformat('Y/n/j H:i:s');
|
||||||
return new Verta(); // 1395/12/12 00:11:35
|
return new Verta(); // 1395/12/12 00:11:35
|
||||||
|
|||||||
+70
-1
@@ -401,6 +401,42 @@ class Verta extends DateTime {
|
|||||||
public static function now() {
|
public static function now() {
|
||||||
return new static();
|
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
|
* Create a Verta instance from a DateTime one
|
||||||
@@ -969,6 +1005,17 @@ class Verta extends DateTime {
|
|||||||
return $this->strftime($format);
|
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
|
* Format the instance as date
|
||||||
*
|
*
|
||||||
@@ -1485,7 +1532,29 @@ class Verta extends DateTime {
|
|||||||
return $this->addSeconds(-1 * $value);
|
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
|
* gregorian to jalali convertion
|
||||||
|
|||||||
Reference in new issue
Block a user