Skip to content

Commit

Permalink
Merge branch 'master' into fix/relative-url-x-requested-with
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-nc authored Nov 24, 2023
2 parents 323b6f7 + 704326f commit 8729f37
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions apps/dav/lib/CalDAV/Reminder/Notifier.php
Original file line number Diff line number Diff line change
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

0 comments on commit 8729f37

Please sign in to comment.