Skip to content

Commit

Permalink
/~https://github.com/ChurchCRM/CRM/issues/6990
Browse files Browse the repository at this point in the history
  • Loading branch information
Daeho Baek authored and respencer committed May 7, 2024
1 parent 15df29e commit 55492b0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/ChurchCRM/SystemCalendars/BirthdaysCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ private function peopleCollectionToEvents(ObjectCollection $People): ObjectColle
$birthday = new Event();
$birthday->setId($person->getId());
$birthday->setEditable(false);
$birthday->setStart($year . '-' . $person->getBirthMonth() . '-' . $person->getBirthDay());
$age = $person->getAge($birthday->getStart());
$eventDate = $year . '-' . $person->getBirthMonth() . '-' . $person->getBirthDay();
$birthday->setStart($eventDate);
$age = $person->getAge($eventDate);
$birthday->setTitle($person->getFullName() . ($age ? ' (' . $age . ')' : ''));
$birthday->setURL($person->getViewURI());
$events->push($birthday);
Expand Down
6 changes: 2 additions & 4 deletions src/ChurchCRM/model/ChurchCRM/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public function postSave(ConnectionInterface $con = null): void
parent::postSave($con);
}

public function getAge(?\DateTimeInterface $now = null): ?string
public function getAge(?string $date = null): ?string
{
if ($this->getBirthYear() === null) {
return null;
Expand All @@ -651,9 +651,7 @@ public function getAge(?\DateTimeInterface $now = null): ?string
if (!$birthDate instanceof \DateTimeImmutable || $this->hideAge()) {
return false;
}
if (!$now instanceof \DateTimeInterface) {
$now = new \DateTimeImmutable('today');
}
$now = $date == null ? new \DateTimeImmutable('today') : \DateTimeImmutable::createFromFormat('Y-m-d', $date);
$age = date_diff($now, $birthDate);

if ($age->y < 1) {
Expand Down

0 comments on commit 55492b0

Please sign in to comment.