Fix Deprecated message

Instead of adding a new dynamic property to the DateInterval-Object, a new var is created which stores the weeks. Inside the `foreach` a handler is created by checking, if the current `$key` is `w` for weeks.
This commit is contained in:
Sebastian 2023-02-13 20:58:10 +01:00 committed by GitHub
parent 532140d967
commit 5c260d82f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -663,8 +663,8 @@ class Page {
$past = new DateTime($this->getValue('dateRaw')); $past = new DateTime($this->getValue('dateRaw'));
$elapsed = $current->diff($past); $elapsed = $current->diff($past);
$elapsed->w = floor($elapsed->d / 7); $weeks = floor($elapsed->d / 7);
$elapsed->d -= $elapsed->w * 7; $elapsed->d -= $weeks * 7;
$string = array( $string = array(
'y' => $language->g('year'), 'y' => $language->g('year'),
@ -677,8 +677,11 @@ class Page {
); );
foreach ($string as $key => &$value) { foreach ($string as $key => &$value) {
if ($elapsed->$key) {
$value = $elapsed->$key . ' ' . $value . ($elapsed->$key > 1 ? 's' : ' '); $handle_type = 'w' === $key ? $weeks : $elapsed->$key;
if ($handle_type) {
$value = $handle_type . ' ' . $value . ($handle_type > 1 ? 's' : ' ');
} else { } else {
unset($string[$key]); unset($string[$key]);
} }