Allow to inject/mock `new \DateTime()` similar to time()
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
877823eb9d
commit
840dd4b39c
|
@ -41,5 +41,14 @@ class TimeFactory implements ITimeFactory {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,4 +37,12 @@ interface ITimeFactory {
|
|||
*/
|
||||
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;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue