From 770881d5d66de36bb04fab8a2b9fdcae658150fa Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 23 Jun 2021 15:28:07 +0200 Subject: [PATCH 1/2] Move DateTime::ATOM to DateTimeInterface::ATOM Signed-off-by: Christoph Wurst --- .../CalDAV/Reminder/NotificationProvider/EmailProvider.php | 4 ++-- .../CalDAV/Reminder/NotificationProvider/PushProvider.php | 4 ++-- apps/dav/lib/CalDAV/Reminder/Notifier.php | 6 +++--- apps/dav/lib/CalDAV/Schedule/IMipPlugin.php | 4 ++-- apps/dav/lib/Files/FileSearchBackend.php | 2 +- apps/dav/lib/Search/EventsSearchProvider.php | 4 ++-- apps/dav/lib/Search/TasksSearchProvider.php | 4 ++-- core/Command/Security/ListCertificates.php | 4 ++-- core/Command/User/Info.php | 2 +- core/Command/User/ListCommand.php | 2 +- lib/private/Console/TimestampFormatter.php | 2 +- lib/private/Log/LogDetails.php | 2 +- .../AppFramework/Middleware/NotModifiedMiddlewareTest.php | 4 ++-- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php index 71cdd2cdd6904..456b9f8b42dcf 100644 --- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php +++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php @@ -390,8 +390,8 @@ private function generateDateString(IL10N $l10n, VEvent $vevent):string { $diff = $dtstartDt->diff($dtendDt); - $dtstartDt = new \DateTime($dtstartDt->format(\DateTime::ATOM)); - $dtendDt = new \DateTime($dtendDt->format(\DateTime::ATOM)); + $dtstartDt = new \DateTime($dtstartDt->format(\DateTimeInterface::ATOM)); + $dtendDt = new \DateTime($dtendDt->format(\DateTimeInterface::ATOM)); if ($isAllDay) { // One day event diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php index 7b53fac766a3c..fb123960df825 100644 --- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php +++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php @@ -137,10 +137,10 @@ protected function extractEventDetails(VEvent $vevent):array { ? ((string) $vevent->LOCATION) : null, 'all_day' => $start instanceof Property\ICalendar\Date, - 'start_atom' => $start->getDateTime()->format(\DateTime::ATOM), + 'start_atom' => $start->getDateTime()->format(\DateTimeInterface::ATOM), 'start_is_floating' => $start->isFloating(), 'start_timezone' => $start->getDateTime()->getTimezone()->getName(), - 'end_atom' => $end->getDateTime()->format(\DateTime::ATOM), + 'end_atom' => $end->getDateTime()->format(\DateTimeInterface::ATOM), 'end_is_floating' => $end->isFloating(), 'end_timezone' => $end->getDateTime()->getTimezone()->getName(), ]; diff --git a/apps/dav/lib/CalDAV/Reminder/Notifier.php b/apps/dav/lib/CalDAV/Reminder/Notifier.php index 6dbe95db244d9..8535c55054a90 100644 --- a/apps/dav/lib/CalDAV/Reminder/Notifier.php +++ b/apps/dav/lib/CalDAV/Reminder/Notifier.php @@ -144,7 +144,7 @@ private function prepareReminderNotification(INotification $notification):INotif private function prepareNotificationSubject(INotification $notification): void { $parameters = $notification->getSubjectParameters(); - $startTime = \DateTime::createFromFormat(\DateTime::ATOM, $parameters['start_atom']); + $startTime = \DateTime::createFromFormat(\DateTimeInterface::ATOM, $parameters['start_atom']); $now = $this->timeFactory->getDateTime(); $title = $this->getTitleFromParameters($parameters); @@ -221,8 +221,8 @@ private function getTitleFromParameters(array $parameters):string { * @throws \Exception */ private function generateDateString(array $parameters):string { - $startDateTime = DateTime::createFromFormat(\DateTime::ATOM, $parameters['start_atom']); - $endDateTime = DateTime::createFromFormat(\DateTime::ATOM, $parameters['end_atom']); + $startDateTime = DateTime::createFromFormat(\DateTimeInterface::ATOM, $parameters['start_atom']); + $endDateTime = DateTime::createFromFormat(\DateTimeInterface::ATOM, $parameters['end_atom']); // If the event has already ended, dismiss the notification if ($endDateTime < $this->timeFactory->getDateTime()) { diff --git a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php index 63290e76e617a..18efe6184833a 100644 --- a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php +++ b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php @@ -441,8 +441,8 @@ private function generateWhenString(IL10N $l10n, VEvent $vevent) { $diff = $dtstartDt->diff($dtendDt); - $dtstartDt = new \DateTime($dtstartDt->format(\DateTime::ATOM)); - $dtendDt = new \DateTime($dtendDt->format(\DateTime::ATOM)); + $dtstartDt = new \DateTime($dtstartDt->format(\DateTimeInterface::ATOM)); + $dtendDt = new \DateTime($dtendDt->format(\DateTimeInterface::ATOM)); if ($isAllDay) { // One day event diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php index 1732b0cc85a30..6c759e71c1335 100644 --- a/apps/dav/lib/Files/FileSearchBackend.php +++ b/apps/dav/lib/Files/FileSearchBackend.php @@ -378,7 +378,7 @@ private function castValue(SearchPropertyDefinition $property, $value) { if (is_numeric($value)) { return max(0, 0 + $value); } - $date = \DateTime::createFromFormat(\DateTime::ATOM, $value); + $date = \DateTime::createFromFormat(\DateTimeInterface::ATOM, $value); return ($date instanceof \DateTime && $date->getTimestamp() !== false) ? $date->getTimestamp() : 0; default: return $value; diff --git a/apps/dav/lib/Search/EventsSearchProvider.php b/apps/dav/lib/Search/EventsSearchProvider.php index 5cfa7d30c5ae1..07fc90397ed2d 100644 --- a/apps/dav/lib/Search/EventsSearchProvider.php +++ b/apps/dav/lib/Search/EventsSearchProvider.php @@ -181,8 +181,8 @@ protected function generateSubline(Component $eventComponent): string { $dtStart = $eventComponent->DTSTART; $dtEnd = $this->getDTEndForEvent($eventComponent); $isAllDayEvent = $dtStart instanceof Property\ICalendar\Date; - $startDateTime = new \DateTime($dtStart->getDateTime()->format(\DateTime::ATOM)); - $endDateTime = new \DateTime($dtEnd->getDateTime()->format(\DateTime::ATOM)); + $startDateTime = new \DateTime($dtStart->getDateTime()->format(\DateTimeInterface::ATOM)); + $endDateTime = new \DateTime($dtEnd->getDateTime()->format(\DateTimeInterface::ATOM)); if ($isAllDayEvent) { $endDateTime->modify('-1 day'); diff --git a/apps/dav/lib/Search/TasksSearchProvider.php b/apps/dav/lib/Search/TasksSearchProvider.php index c8f1d0d288b62..763720ee4ae0a 100644 --- a/apps/dav/lib/Search/TasksSearchProvider.php +++ b/apps/dav/lib/Search/TasksSearchProvider.php @@ -153,13 +153,13 @@ protected function getDeepLinkToTasksApp(string $calendarUri, */ protected function generateSubline(Component $taskComponent): string { if ($taskComponent->COMPLETED) { - $completedDateTime = new \DateTime($taskComponent->COMPLETED->getDateTime()->format(\DateTime::ATOM)); + $completedDateTime = new \DateTime($taskComponent->COMPLETED->getDateTime()->format(\DateTimeInterface::ATOM)); $formattedDate = $this->l10n->l('date', $completedDateTime, ['width' => 'medium']); return $this->l10n->t('Completed on %s', [$formattedDate]); } if ($taskComponent->DUE) { - $dueDateTime = new \DateTime($taskComponent->DUE->getDateTime()->format(\DateTime::ATOM)); + $dueDateTime = new \DateTime($taskComponent->DUE->getDateTime()->format(\DateTimeInterface::ATOM)); $formattedDate = $this->l10n->l('date', $dueDateTime, ['width' => 'medium']); if ($taskComponent->DUE->hasTime()) { diff --git a/core/Command/Security/ListCertificates.php b/core/Command/Security/ListCertificates.php index 9a96d98e53f03..9a99a2f6db637 100644 --- a/core/Command/Security/ListCertificates.php +++ b/core/Command/Security/ListCertificates.php @@ -58,10 +58,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'name' => $certificate->getName(), 'common_name' => $certificate->getCommonName(), 'organization' => $certificate->getOrganization(), - 'expire' => $certificate->getExpireDate()->format(\DateTime::ATOM), + 'expire' => $certificate->getExpireDate()->format(\DateTimeInterface::ATOM), 'issuer' => $certificate->getIssuerName(), 'issuer_organization' => $certificate->getIssuerOrganization(), - 'issue_date' => $certificate->getIssueDate()->format(\DateTime::ATOM) + 'issue_date' => $certificate->getIssueDate()->format(\DateTimeInterface::ATOM) ]; }, $this->certificateManager->listCertificates()); if ($outputType === self::OUTPUT_FORMAT_JSON) { diff --git a/core/Command/User/Info.php b/core/Command/User/Info.php index eff13378278e6..e6ba691a40dbe 100644 --- a/core/Command/User/Info.php +++ b/core/Command/User/Info.php @@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'enabled' => $user->isEnabled(), 'groups' => $groups, 'quota' => $user->getQuota(), - 'last_seen' => date(\DateTime::ATOM, $user->getLastLogin()), // ISO-8601 + 'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601 'user_directory' => $user->getHome(), 'backend' => $user->getBackendClassName() ]; diff --git a/core/Command/User/ListCommand.php b/core/Command/User/ListCommand.php index a30b1cae1184e..3a2708d4da233 100644 --- a/core/Command/User/ListCommand.php +++ b/core/Command/User/ListCommand.php @@ -109,7 +109,7 @@ private function formatUsers(array $users, bool $detailed = false) { 'enabled' => $user->isEnabled(), 'groups' => $groups, 'quota' => $user->getQuota(), - 'last_seen' => date(\DateTime::ATOM, $user->getLastLogin()), // ISO-8601 + 'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601 'user_directory' => $user->getHome(), 'backend' => $user->getBackendClassName() ]; diff --git a/lib/private/Console/TimestampFormatter.php b/lib/private/Console/TimestampFormatter.php index fcaa6ebfbf1f7..59e480b39e8d8 100644 --- a/lib/private/Console/TimestampFormatter.php +++ b/lib/private/Console/TimestampFormatter.php @@ -103,7 +103,7 @@ public function format($message) { $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null; $time = new \DateTime('now', $timeZone); - $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); + $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTimeInterface::ATOM)); return $timestampInfo . ' ' . $this->formatter->format($message); } diff --git a/lib/private/Log/LogDetails.php b/lib/private/Log/LogDetails.php index 5ca8231eecb0c..87ce0396594f9 100644 --- a/lib/private/Log/LogDetails.php +++ b/lib/private/Log/LogDetails.php @@ -37,7 +37,7 @@ public function __construct(SystemConfig $config) { public function logDetails(string $app, $message, int $level): array { // default to ISO8601 - $format = $this->config->getValue('logdateformat', \DateTime::ATOM); + $format = $this->config->getValue('logdateformat', \DateTimeInterface::ATOM); $logTimeZone = $this->config->getValue('logtimezone', 'UTC'); try { $timezone = new \DateTimeZone($logTimeZone); diff --git a/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php b/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php index 89ae75bcac233..3cd3921ce4550 100644 --- a/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php @@ -62,11 +62,11 @@ public function dataModified(): array { ['etag', '"etag"', null, '', true], [null, '', $now, $now->format(\DateTime::RFC2822), true], - [null, '', $now, $now->format(\DateTime::ATOM), false], + [null, '', $now, $now->format(\DateTimeInterface::ATOM), false], [null, '', null, $now->format(\DateTime::RFC2822), false], [null, '', $now, '', false], - ['etag', '"etag"', $now, $now->format(\DateTime::ATOM), true], + ['etag', '"etag"', $now, $now->format(\DateTimeInterface::ATOM), true], ['etag', '"etag"', $now, $now->format(\DateTime::RFC2822), true], ]; } From 6d5cfe0c66f7010d552f0aa234a13c2e91a933bd Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 23 Jun 2021 15:30:43 +0200 Subject: [PATCH 2/2] Move DateTime::RFC2822 to DateTimeInterface::2822 Signed-off-by: Christoph Wurst --- apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php | 2 +- .../AppFramework/Middleware/NotModifiedMiddleware.php | 2 +- lib/private/Files/ObjectStore/S3Signature.php | 2 +- lib/public/AppFramework/Http/Response.php | 4 ++-- .../AppFramework/Middleware/NotModifiedMiddlewareTest.php | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php b/apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php index 4d33367b3457c..614ddabb7efbf 100644 --- a/apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php +++ b/apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php @@ -76,7 +76,7 @@ public function getProperties($properties) { return [ '{DAV:}getcontentlength' => 42, - '{DAV:}getlastmodified' => $datetime->format(\DateTime::RFC2822), + '{DAV:}getlastmodified' => $datetime->format(\DateTimeInterface::RFC2822), ]; } diff --git a/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php b/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php index dd3f202b6c1e5..4ebdf10f403b3 100644 --- a/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php +++ b/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php @@ -46,7 +46,7 @@ public function afterController($controller, $methodName, Response $response) { } $modifiedSinceHeader = $this->request->getHeader('IF_MODIFIED_SINCE'); - if ($modifiedSinceHeader !== '' && $response->getLastModified() !== null && trim($modifiedSinceHeader) === $response->getLastModified()->format(\DateTime::RFC2822)) { + if ($modifiedSinceHeader !== '' && $response->getLastModified() !== null && trim($modifiedSinceHeader) === $response->getLastModified()->format(\DateTimeInterface::RFC2822)) { $response->setStatus(Http::STATUS_NOT_MODIFIED); return $response; } diff --git a/lib/private/Files/ObjectStore/S3Signature.php b/lib/private/Files/ObjectStore/S3Signature.php index ec2e6bbe3ac07..1e5ef6978351d 100644 --- a/lib/private/Files/ObjectStore/S3Signature.php +++ b/lib/private/Files/ObjectStore/S3Signature.php @@ -129,7 +129,7 @@ private function prepareRequest( ) { $modify = [ 'remove_headers' => ['X-Amz-Date'], - 'set_headers' => ['Date' => gmdate(\DateTime::RFC2822)] + 'set_headers' => ['Date' => gmdate(\DateTimeInterface::RFC2822)] ]; // Add the security token header if one is being used by the credentials diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index e28fa0b2c8162..ee10d483b25e2 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -115,7 +115,7 @@ public function cacheFor(int $cacheSeconds, bool $public = false) { $time = \OC::$server->query(ITimeFactory::class); $expires->setTimestamp($time->getTime()); $expires->add(new \DateInterval('PT'.$cacheSeconds.'S')); - $this->addHeader('Expires', $expires->format(\DateTime::RFC2822)); + $this->addHeader('Expires', $expires->format(\DateTimeInterface::RFC2822)); } else { $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); unset($this->headers['Expires'], $this->headers['Pragma']); @@ -244,7 +244,7 @@ public function getHeaders() { if ($this->lastModified) { $mergeWith['Last-Modified'] = - $this->lastModified->format(\DateTime::RFC2822); + $this->lastModified->format(\DateTimeInterface::RFC2822); } $this->headers['Content-Security-Policy'] = $this->getContentSecurityPolicy()->buildPolicy(); diff --git a/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php b/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php index 3cd3921ce4550..c62384302fbbb 100644 --- a/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php @@ -61,13 +61,13 @@ public function dataModified(): array { [null, '"etag"', null, '', false], ['etag', '"etag"', null, '', true], - [null, '', $now, $now->format(\DateTime::RFC2822), true], + [null, '', $now, $now->format(\DateTimeInterface::RFC2822), true], [null, '', $now, $now->format(\DateTimeInterface::ATOM), false], - [null, '', null, $now->format(\DateTime::RFC2822), false], + [null, '', null, $now->format(\DateTimeInterface::RFC2822), false], [null, '', $now, '', false], ['etag', '"etag"', $now, $now->format(\DateTimeInterface::ATOM), true], - ['etag', '"etag"', $now, $now->format(\DateTime::RFC2822), true], + ['etag', '"etag"', $now, $now->format(\DateTimeInterface::RFC2822), true], ]; }