Allow to inject/mock `new \DateTime()` similar to time()

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-10-09 15:24:28 +02:00
parent 877823eb9d
commit 840dd4b39c
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 19 additions and 2 deletions

View File

@ -37,9 +37,18 @@ class TimeFactory implements ITimeFactory {
/** /**
* @return int the result of a call to time() * @return int the result of a call to time()
*/ */
public function getTime() : int { public function getTime(): int {
return time(); return time();
} }
/**
* @param string $time
* @param \DateTimeZone $timezone
* @return \DateTime
* @since 15.0.0
*/
public function getDateTime(string $time = 'now', \DateTimeZone $timezone = null): \DateTime {
return new \DateTime($time, $timezone);
}
} }

View File

@ -35,6 +35,14 @@ interface ITimeFactory {
* @return int the result of a call to time() * @return int the result of a call to time()
* @since 8.0.0 * @since 8.0.0
*/ */
public function getTime() : int; public function getTime(): int;
/**
* @param string $time
* @param \DateTimeZone $timezone
* @return \DateTime
* @since 15.0.0
*/
public function getDateTime(string $time = 'now', \DateTimeZone $timezone = null): \DateTime;
} }