Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions lib/private/L10N/L10N.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/public/IL10N.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/public/Sharing/Property/ADateSharePropertyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/L10N/L10nTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Test\L10N;

use DateTime;
use DateTimeImmutable;
use OC\L10N\Factory;
use OC\L10N\L10N;
use OCP\App\IAppManager;
Expand Down Expand Up @@ -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')],
Expand Down
Loading