diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-10-10 14:54:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-10 14:54:15 +0200 |
commit | 0acae1d4aa45ea45428cc034f293f43c0f9430dc (patch) | |
tree | 2a32e5b33788248ac32cd217309d00f82b2cdd45 /lib | |
parent | eac04adaddafc36bd8fc9f81cf6df12ed1050356 (diff) | |
parent | 78cc4171ee410660771bccc479a64e8d50139c24 (diff) | |
download | nextcloud-server-0acae1d4aa45ea45428cc034f293f43c0f9430dc.tar.gz nextcloud-server-0acae1d4aa45ea45428cc034f293f43c0f9430dc.zip |
Merge pull request #11719 from nextcloud/techdebt/noid/allow-to-mock-new-datetime
Allow to inject/mock `new \DateTime()` similar to time()
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/AppFramework/Utility/TimeFactory.php | 11 | ||||
-rw-r--r-- | lib/public/AppFramework/Utility/ITimeFactory.php | 10 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/private/AppFramework/Utility/TimeFactory.php b/lib/private/AppFramework/Utility/TimeFactory.php index fc3bf72609f..4526f9b1abb 100644 --- a/lib/private/AppFramework/Utility/TimeFactory.php +++ b/lib/private/AppFramework/Utility/TimeFactory.php @@ -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); + } } diff --git a/lib/public/AppFramework/Utility/ITimeFactory.php b/lib/public/AppFramework/Utility/ITimeFactory.php index 7951d6ad8e6..0367f037a6e 100644 --- a/lib/public/AppFramework/Utility/ITimeFactory.php +++ b/lib/public/AppFramework/Utility/ITimeFactory.php @@ -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; } |