Browse Source

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

Signed-off-by: Joas Schilling <coding@schilljs.com>
tags/v15.0.0beta1
Joas Schilling 5 years ago
parent
commit
840dd4b39c
No account linked to committer's email address

+ 10
- 1
lib/private/AppFramework/Utility/TimeFactory.php View File

@@ -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);
}

}

+ 9
- 1
lib/public/AppFramework/Utility/ITimeFactory.php View File

@@ -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…
Cancel
Save