Skip to content

Commit

Permalink
subtractHours in DateTimeUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
doganoo committed Dec 14, 2018
1 parent d7481a6 commit 1502cf6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Util/DateTimeUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,22 @@ private function __construct() {
}

/**
* returns the actual unix timestamp
*
* @return int
* @throws \Exception
*/
public static function getUnixTimestamp(): int {
return (new \DateTime())->getTimestamp();
}

/**
* @param int $hours
* @param \DateTime|null $dateTime
* @return \DateTime
* @throws \Exception
*/
public function subtractHours(int $hours, \DateTime $dateTime = null): \DateTime {
if (null === $dateTime) $dateTime = new \DateTime();
$dateTime->modify("-$hours hours");
return $dateTime;
}
}

0 comments on commit 1502cf6

Please sign in to comment.