Birthday Age instead of Year NC 12

Hello,

i want that the Age is shown instead of the year in the Birthday calendar.

This solution does not work on NC 12: [Help] Birthday calendar entry - showing also the age on the title

Anyone can help?

Hello,

i found a solution in “/apps/dav/lib/CalDAV/BirthdayService.php”

replace

		$unknownYear = false;
	if (!$dateParts['year']) {
		$birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];

		$unknownYear = true;
	}

	try {
		$date = new \DateTime($birthday);
	} catch (Exception $e) {
		return null;
	}
	if ($unknownYear) {
		$summary = $doc->FN->getValue() . ' ' . $summarySymbol;
	} else {
		$year = (int)$date->format('Y');
		$summary = $doc->FN->getValue() . " ($summarySymbol$year)";
	}

with

		$actyear = date('Y', time());
	$age = (int)$actyear - (int)substr((string)$birthday, 0, 4);
	$unknownYear = false;
	if (!$dateParts['year']) {
		$birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];

		$unknownYear = true;
	}

	try {
		$date = new \DateTime($birthday);
	} catch (Exception $e) {
		return null;
	}
	if ($unknownYear) {
		$summary = $doc->FN->getValue() . ' ' . $summarySymbol;
	} else {
		$year = (int)$date->format('Y');
		$summary = $doc->FN->getValue() . " ($summarySymbol$year) [$age] ";
	}
1 Like

very well done, i think!

the problem might be that with every update you need to rechange the code in said file again.
so would you pls file an issue in gh (https://github.com/nextcloud/calendar) and present this codechange as a solution or make an app by yourself that would extend the calendar-app? :wink:

this way your changes would survive every update…

https://github.com/nextcloud/server/pull/6561

Hi,

I know this is an old topic but at least I searched for it instead of posting a new one :slight_smile:

The mentioned Pull Request to improve the calendar entrys has been closed unsuccessful, i could not find newer topics that adress this issue.
Don’t get me wrong the birthday calendar is great, but it would be even better if you could see how old a person got with one glance at the entry instead of starting to calculate in the head.
If i understand correctly from the Pull Request the difficulty lies in the calendar entry being static while the age changes every year.
I see two ways to work around that:

  1. Changing the Format of calendar entrys to support a birthyear and changing every calendar app in the world to know how to handle that (very unlikely)
  2. Create a new calendar entry for every year with the right age for every person in the contacts

The obvious choice for me would be option two since it is the only choice that can be solved by NC alone. It would mean more calendar entrys though which influences processing speed and filesize of the calendar (resulting in more data strain for mobile users if they sync the calendar regularly). For me that would be a tradeoff i am willing to take, but I can only speak for myself.

Does this make sense or am I missing something?

greetings

STonE