feat(ITimeFactory): Implement createFromFormat

Allow usage of \DateTime::createFromFormat from the ITimeFactory

Signed-off-by: Micke Nordin <kano@sunet.se>
This commit is contained in:
Micke Nordin 2025-03-14 09:09:03 +01:00 committed by Micke Nordin
parent a178acfa1c
commit 42cb346efd
2 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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