mirror of
https://github.com/nextcloud/server.git
synced 2026-03-08 00:11:03 -05:00
fix(dav): Avoid date diffing if PHP is buggy
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
eeba809a52
commit
096537eae5
1 changed files with 22 additions and 8 deletions
|
|
@ -170,20 +170,34 @@ 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 (!$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]);
|
||||
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
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue