From af8c47a5aa6875c206b75cf408316c550922e4a7 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 28 Jul 2026 09:44:34 +0200 Subject: [PATCH 1/2] fix(L10N): Also accept DateTimeImmutable Signed-off-by: provokateurin --- lib/private/L10N/L10N.php | 24 +----------------------- lib/public/IL10N.php | 2 +- tests/lib/L10N/L10nTest.php | 9 +++++++++ 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/lib/private/L10N/L10N.php b/lib/private/L10N/L10N.php index 87740567c8359..be5b56cda649e 100644 --- a/lib/private/L10N/L10N.php +++ b/lib/private/L10N/L10N.php @@ -95,28 +95,6 @@ public function n(string $text_singular, string $text_plural, int $count, array return (string)new L10NString($this, $text_plural, $parameters, $count); } - /** - * Localization - * @param string $type Type of localization - * @param \DateTime|int|string|null $data parameters for this localization - * @param array $options - * @return string|int|false - * - * Returns the localized data. - * - * Implemented types: - * - date - * - Creates a date - * - params: timestamp (int/string) - * - datetime - * - Creates date and time - * - params: timestamp (int/string) - * - time - * - Creates a time - * - params: timestamp (int/string) - * - firstday: Returns the first day of the week (0 sunday - 6 saturday) - * - jsdate: Returns the short JS date format - */ #[\Override] public function l(string $type, $data = null, array $options = []) { if ($this->locale === null) { @@ -135,7 +113,7 @@ public function l(string $type, $data = null, array $options = []) { } $value = new \DateTime(); - if ($data instanceof \DateTime) { + if ($data instanceof \DateTime || $data instanceof \DateTimeImmutable) { $value = $data; } elseif (\is_string($data) && !is_numeric($data)) { $data = strtotime($data); diff --git a/lib/public/IL10N.php b/lib/public/IL10N.php index 6c4690f9fe70a..277df33fdcc4b 100644 --- a/lib/public/IL10N.php +++ b/lib/public/IL10N.php @@ -50,7 +50,7 @@ public function n(string $text_singular, string $text_plural, int $count, array /** * Localization * @param string $type Type of localization - * @param \DateTime|int|string|null $data parameters for this localization + * @param \DateTime|\DateTimeImmutable|int|string|null $data parameters for this localization * @param array $options currently supports following options: * - 'width': handed into \Punic\Calendar::formatDate as second parameter * @return string|int|false diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php index 842f1bc5eda88..3166fbba8e9c7 100644 --- a/tests/lib/L10N/L10nTest.php +++ b/tests/lib/L10N/L10nTest.php @@ -9,6 +9,7 @@ namespace Test\L10N; use DateTime; +use DateTimeImmutable; use OC\L10N\Factory; use OC\L10N\L10N; use OCP\App\IAppManager; @@ -146,6 +147,14 @@ public static function localizationData(): array { ["11:31:30\xE2\x80\xAFPM GMT+0", 'en', 'en_US', 'time', new DateTime('@1234567890')], ['23:31:30 GMT+0', 'de', 'de_DE', 'time', new DateTime('@1234567890')], + // DateTimeImmutable object + ["February 13, 2009, 11:31:30\xE2\x80\xAFPM GMT+0", 'en', 'en_US', 'datetime', new DateTimeImmutable('@1234567890')], + ['13. Februar 2009, 23:31:30 GMT+0', 'de', 'de_DE', 'datetime', new DateTimeImmutable('@1234567890')], + ['February 13, 2009', 'en', 'en_US', 'date', new DateTimeImmutable('@1234567890')], + ['13. Februar 2009', 'de', 'de_DE', 'date', new DateTimeImmutable('@1234567890')], + ["11:31:30\xE2\x80\xAFPM GMT+0", 'en', 'en_US', 'time', new DateTimeImmutable('@1234567890')], + ['23:31:30 GMT+0', 'de', 'de_DE', 'time', new DateTimeImmutable('@1234567890')], + // en_GB ['13 February 2009, 23:31:30 GMT+0', 'en_GB', 'en_GB', 'datetime', new DateTime('@1234567890')], ['13 February 2009', 'en_GB', 'en_GB', 'date', new DateTime('@1234567890')], From eaa2d89e7fb8e9df72abcb97ec7932cbee39add3 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 28 Jul 2026 09:45:10 +0200 Subject: [PATCH 2/2] fix(Sharing): Improve date error messages Signed-off-by: provokateurin --- lib/public/Sharing/Property/ADateSharePropertyType.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/public/Sharing/Property/ADateSharePropertyType.php b/lib/public/Sharing/Property/ADateSharePropertyType.php index 3d91890c17395..510e08981e2e2 100644 --- a/lib/public/Sharing/Property/ADateSharePropertyType.php +++ b/lib/public/Sharing/Property/ADateSharePropertyType.php @@ -46,15 +46,17 @@ public function validateValue(IFactory $l10nFactory, Share $share, string $value } if ($date === false) { - return $l10nFactory->get(Application::APP_ID)->t('Invalid ISO date: %s', [$value]); + return $l10nFactory->get(Application::APP_ID)->t('Invalid ISO8601 date: %s', [$value]); } if (($minDate = $this->getMinDate($share)) instanceof DateTimeImmutable && $date->diff($minDate)->invert === 0) { - return $l10nFactory->get(Application::APP_ID)->t('Date needs to be after %1$s: %2$s', [$minDate->format(DateTimeInterface::ATOM), $value]); + $l10n = $l10nFactory->get(Application::APP_ID); + return $l10n->t('Date needs to be after %s', [$l10n->l('datetime', $minDate)]); } if (($maxDate = $this->getMaxDate($share)) instanceof DateTimeImmutable && $date->diff($maxDate)->invert === 1) { - return $l10nFactory->get(Application::APP_ID)->t('Date needs to be before %1$s: %2$s', [$maxDate->format(DateTimeInterface::ATOM), $value]); + $l10n = $l10nFactory->get(Application::APP_ID); + return $l10n->t('Date needs to be before %s', [$l10n->l('datetime', $maxDate)]); } return true;