From 42cb346efd34c216dc9e9d66ff2c5f2b6dce431a Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Fri, 14 Mar 2025 09:09:03 +0100 Subject: [PATCH] feat(ITimeFactory): Implement createFromFormat Allow usage of \DateTime::createFromFormat from the ITimeFactory Signed-off-by: Micke Nordin --- lib/private/AppFramework/Utility/TimeFactory.php | 11 +++++++++++ lib/public/AppFramework/Utility/ITimeFactory.php | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/private/AppFramework/Utility/TimeFactory.php b/lib/private/AppFramework/Utility/TimeFactory.php index 0584fd05ef9..2f6f081935a 100644 --- a/lib/private/AppFramework/Utility/TimeFactory.php +++ b/lib/private/AppFramework/Utility/TimeFactory.php @@ -24,6 +24,17 @@ class TimeFactory implements ITimeFactory { $this->timezone = new \DateTimeZone('UTC'); } + /** + * @param string $format + * @param string $time + * @param \DateTimeZone|null $timezone + * @return \DateTime with the result of a call to \DateTime::createFromFormat() + * @since 32.0.0 + */ + public function createFromFormat(string $format, string $time = 'now', ?\DateTimeZone $timezone = null): \DateTime { + return \DateTime::createFromFormat($format, $time, $timezone); + } + /** * @return int the result of a call to time() * @since 8.0.0 diff --git a/lib/public/AppFramework/Utility/ITimeFactory.php b/lib/public/AppFramework/Utility/ITimeFactory.php index cd63b94dee3..4d823b54efa 100644 --- a/lib/public/AppFramework/Utility/ITimeFactory.php +++ b/lib/public/AppFramework/Utility/ITimeFactory.php @@ -20,6 +20,14 @@ use Psr\Clock\ClockInterface; */ interface ITimeFactory extends ClockInterface { + /** + * @param string $format + * @param string $time + * @param \DateTimeZone|null $timezone + * @return \DateTime with the result of a call to \DateTime::createFromFormat() + * @since 32.0.0 + */ + public function createFromFormat(string $format, string $time = 'now', ?\DateTimeZone $timezone = null): \DateTime; /** * @return int the result of a call to time() * @since 8.0.0