Skip to content
Permalink
Browse files

DateTime: Change return self to static

  • Loading branch information...
mabar committed Sep 24, 2019
1 parent 2b82082 commit ec703d393048dd54c684dc6997c4ffdd8f09f0f4
Showing with 34 additions and 0 deletions.
  1. +34 −0 src/DateTime.php
@@ -16,6 +16,7 @@ public function __construct(string $time = 'now', ?DateTimeZone $timezone = null
/**
* @param string|int|DateTimeInterface $time
* @return static
*/
public static function from($time): self
{
@@ -24,6 +25,7 @@ public static function from($time): self
/**
* @param string $modify
* @return static
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
*/
public function modifyClone($modify = ''): self
@@ -33,6 +35,8 @@ public function modifyClone($modify = ''): self
/**
* Set time to current time
*
* @return static
*/
public function setCurrentTime(): self
{
@@ -41,6 +45,8 @@ public function setCurrentTime(): self
/**
* Reset current time (00:00:00)
*
* @return static
*/
public function resetTime(): self
{
@@ -49,6 +55,8 @@ public function resetTime(): self
/**
* Reset current time (00:00:00)
*
* @return static
*/
public function setZeroTime(): self
{
@@ -57,6 +65,8 @@ public function setZeroTime(): self
/**
* Set time to midnight (23:59:59)
*
* @return static
*/
public function setMidnight(): self
{
@@ -65,12 +75,17 @@ public function setMidnight(): self
/**
* Set date to today
*
* @return static
*/
public function setToday(): self
{
return $this->modifyClone()->setDate((int) date('Y'), (int) date('m'), (int) date('d'));
}
/**
* @return static
*/
public static function createBy(?int $year = null, ?int $month = null, ?int $day = null, ?int $hour = null, ?int $minute = null, ?int $second = null): self
{
return self::create([
@@ -85,6 +100,7 @@ public static function createBy(?int $year = null, ?int $month = null, ?int $day
/**
* @param string[]|int[]|null[] $args
* @return static
*/
public static function create(array $args): self
{
@@ -120,36 +136,54 @@ public static function create(array $args): self
return $date;
}
/**
* @return static
*/
public function getFirstDayOfWeek(): self
{
return $this->modifyClone('first day of this week')
->setZeroTime();
}
/**
* @return static
*/
public function getLastDayOfWeek(): self
{
return $this->modifyClone('last day of this week')
->setMidnight();
}
/**
* @return static
*/
public function getFirstDayOfMonth(): self
{
return $this->modifyClone('first day of this month')
->setZeroTime();
}
/**
* @return static
*/
public function getLastDayOfMonth(): self
{
return $this->modifyClone('last day of this month')
->setMidnight();
}
/**
* @return static
*/
public function getFirstDayOfYear(): self
{
return $this->modifyClone(sprintf('first day of January %s', $this->format('Y')))
->setZeroTime();
}
/**
* @return static
*/
public function getLastDayOfYear(): self
{
return $this->modifyClone(sprintf('last day of December %s', $this->format('Y')))

0 comments on commit ec703d3

Please sign in to comment.
You can’t perform that action at this time.