Add birthdate to wishlist name suggestion

This commit is contained in:
Jay Trees 2022-03-23 15:11:13 +01:00
parent 89307c571b
commit 7f694cb41a

View file

@ -8,18 +8,32 @@
function getWishlistNameSuggestion(): string function getWishlistNameSuggestion(): string
{ {
global $user;
$now = time(); $now = time();
$month = date('n'); $month = date('n');
$season = ''; $name = '';
$startOfBirthdate = null;
$startOfEaster = strtotime('15. April'); // Approximate $startOfEaster = strtotime('15. April'); // Approximate
$startOfChristmas = strtotime('24. December'); $startOfChristmas = strtotime('24. December');
if ($now <= $startOfEaster) { if ($user->birthdate) {
$season = 'Easter'; $birthdates = explode('-', $user->birthdate);
} elseif ($now <= $startOfChristmas) {
$season = 'Christmas'; $birthdate = new \DateTime();
$birthdate->setDate(date('Y'), $birthdates[1], $birthdates[2]);
$startOfBirthdate = $birthdate->getTimestamp();
} }
return $season; if ($startOfBirthdate && $now <= $startOfBirthdate) {
$name = 'Birthday';
} elseif ($now <= $startOfEaster) {
$name = 'Easter';
} elseif ($now <= $startOfChristmas) {
$name = 'Christmas';
}
return $name;
} }