Fix birthday with hidden year in a language-specific format (#5205)

* Fix birthday with hidden year in a language-specific format

* Update Birthday.php

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
This commit is contained in:
Yuriy Bakhtin 2021-07-28 18:56:31 +03:00 committed by GitHub
parent bda35f5f4b
commit 2623fdad69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -8,6 +8,7 @@ HumHub Changelog
- Fix #5172: Missing translations for "New Member" and "New Spaces" directory widgets
- Fix #5195: Fix export users with tags data
- Fix #5200: Auto creating following for friends
- Fix #5187: Fix birthday with hidden year in a language-specific format
- Enh #5189: Reduce minimum character limit for tags to 2 chars

View File

@ -199,11 +199,22 @@ class Birthday extends BaseType
}
}
$longDate = Yii::$app->formatter->asDate($birthdayDate, 'long');
/*
* - user set hide age yes
*/
if ($hideAge === self::HIDE_AGE_YES) {
return Yii::$app->formatter->asDate($birthdayDate, 'dd. MMMM');
// See: https://github.com/humhub/humhub/issues/5187#issuecomment-888178022
$month = Yii::$app->formatter->asDate($birthdayDate, 'php:F');
$day = Yii::$app->formatter->asDate($birthdayDate, 'php:d');
if (preg_match('/(' . preg_quote($day) . '.+' . preg_quote($month) . '|' . preg_quote($month) . '.+' . preg_quote($day) . ')/', $longDate, $m)) {
return $m[0];
}
$year = Yii::$app->formatter->asDate($birthdayDate, 'php:Y');
return preg_replace('/[,\s]*' . preg_quote($year) . '([^\d]+|$)/', '', $longDate);
}
$ageInYears = Yii::t(
@ -212,7 +223,7 @@ class Birthday extends BaseType
['%y' => $birthdayDate->diff(new \DateTime())->y]
);
return Yii::$app->formatter->asDate($birthdayDate, 'long') . ' (' . $ageInYears . ')';
return $longDate . ' (' . $ageInYears . ')';
}
/**