1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2025-05-21 23:21:15 +02:00

feat(date): add date_get_age

Fixes #7
This commit is contained in:
2024-10-08 08:47:16 +02:00
parent 95ad9f24f4
commit b0fd3bf373
4 changed files with 46 additions and 0 deletions

View File

@ -329,3 +329,11 @@ struct date *date_get_now_local() {
return date;
}
uint16_t date_get_age(struct date *birth_date, struct date *current_date) {
uint16_t age = current_date->year - birth_date->year;
if (current_date->month < birth_date->month || (current_date->month == birth_date->month && current_date->day < birth_date->day)) {
age--;
}
return age;
}

View File

@ -338,4 +338,13 @@ struct date *date_get_now_utc();
*/
struct date *date_get_now_local();
/**
* @brief Calculates the age of a person based on their birth date.
*
* @param birth_date
* @return uint16_t
* @since v5.1.0
*/
uint16_t date_get_age(struct date *birth_date, struct date *current_date);
#endif