Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] fix(dav): Avoid date diffing if PHP is buggy #41726

Merged
merged 1 commit into from Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 23 additions & 9 deletions apps/dav/lib/CalDAV/Reminder/Notifier.php
Expand Up @@ -170,20 +170,34 @@ private function prepareNotificationSubject(INotification $notification): void {
$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
*
Expand Down