mirror of
https://github.com/nextcloud/server.git
synced 2026-04-29 18:11:41 -04:00
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
2 changed files with 19 additions and 2 deletions
|
|
@ -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 a new issue