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
|
@ -37,9 +37,18 @@ class TimeFactory implements ITimeFactory {
|
|||
/**
|
||||
* @return int the result of a call to time()
|
||||
*/
|
||||
public function getTime() : int {
|
||||
public function getTime(): int {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,14 @@ interface ITimeFactory {
|
|||
* @return int the result of a call to time()
|
||||
* @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;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue