summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2023-11-24 09:45:56 +0100
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>2023-11-24 10:43:48 +0000
commit69b9a56bbb423b3b2aff7d17690a389536128d3b (patch)
treedddffc37f23a2874c90c5f12ba3d96594e535993 /apps/dav
parent0af2125a82f23ad337ca2ad12ac034ca72409e96 (diff)
downloadnextcloud-server-69b9a56bbb423b3b2aff7d17690a389536128d3b.tar.gz
nextcloud-server-69b9a56bbb423b3b2aff7d17690a389536128d3b.zip
fix(dav): Avoid date diffing if PHP is buggy
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CalDAV/Reminder/Notifier.php32
1 files changed, 23 insertions, 9 deletions
diff --git a/apps/dav/lib/CalDAV/Reminder/Notifier.php b/apps/dav/lib/CalDAV/Reminder/Notifier.php
index c658ef2ff01..32683e43b82 100644
--- a/apps/dav/lib/CalDAV/Reminder/Notifier.php
+++ b/apps/dav/lib/CalDAV/Reminder/Notifier.php
@@ -170,21 +170,35 @@ class Notifier implements INotifier {
$components[] = $this->l10n->n('%n minute', '%n minutes', $diff->i);
}
- // Limiting to the first three components to prevent
- // the string from getting too long
- $firstThreeComponents = array_slice($components, 0, 2);
- $diffLabel = implode(', ', $firstThreeComponents);
-
- if ($diff->invert) {
- $title = $this->l10n->t('%s (in %s)', [$title, $diffLabel]);
- } else {
- $title = $this->l10n->t('%s (%s ago)', [$title, $diffLabel]);
+ if (!$this->hasPhpDatetimeDiffBug()) {
+ // Limiting to the first three components to prevent
+ // the string from getting too long
+ $firstThreeComponents = array_slice($components, 0, 2);
+ $diffLabel = implode(', ', $firstThreeComponents);
+
+ if ($diff->invert) {
+ $title = $this->l10n->t('%s (in %s)', [$title, $diffLabel]);
+ } else {
+ $title = $this->l10n->t('%s (%s ago)', [$title, $diffLabel]);
+ }
}
$notification->setParsedSubject($title);
}
/**
+ * @see https://github.com/nextcloud/server/issues/41615
+ * @see https://github.com/php/php-src/issues/9699
+ */
+ private function hasPhpDatetimeDiffBug(): bool {
+ $d1 = DateTime::createFromFormat(\DateTimeInterface::ATOM, '2023-11-22T11:52:00+01:00');
+ $d2 = new DateTime('2023-11-22T10:52:03', new \DateTimeZone('UTC'));
+
+ // The difference is 3 seconds, not -1year+11months+…
+ return $d1->diff($d2)->y < 0;
+ }
+
+ /**
* Sets the notification message based on the parameters set in PushProvider
*
* @param INotification $notification