aboutsummaryrefslogtreecommitdiffstats
path: root/get-contact-birthday.c
diff options
context:
space:
mode:
Diffstat (limited to 'get-contact-birthday.c')
-rw-r--r--get-contact-birthday.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/get-contact-birthday.c b/get-contact-birthday.c
index 29be768..173d6a2 100644
--- a/get-contact-birthday.c
+++ b/get-contact-birthday.c
@@ -18,7 +18,8 @@ get_age(struct libcontacts_birthday *bday, const struct tm *now)
static void
print_birthdate(struct libcontacts_birthday *bday, const struct tm *now)
{
- int age;
+ static const int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+ int age, days = 0, y, m, d;
if (bday->year)
printf("%04u-", bday->year);
else
@@ -39,7 +40,20 @@ print_birthdate(struct libcontacts_birthday *bday, const struct tm *now)
}
if (bday->year && bday->month && bday->day) {
age = get_age(bday, now);
- printf(", %i %s old today", age, age == 1 ? "year" : "years");
+ y = (int)bday->year - 1900;
+ m = (int)bday->month - 1;
+ d = (int)bday->day;
+ while (m != now->tm_mon || d > now->tm_mday) {
+ days += days_in_month[m] - (d - 1);
+ days += (m == 1 && y % 4 == 0 && (y % 100 || y % 400 == 0));
+ d = 1;
+ if (++m == 12) {
+ y += 1;
+ m = 0;
+ }
+ }
+ days += now->tm_mday - d;
+ printf(", %i %s and %i %s old", age, age == 1 ? "year" : "years", days, days == 1 ? "day" : "days");
}
printf("\n");
}
@@ -70,7 +84,7 @@ print_birthday(struct libcontacts_birthday *bday, const struct tm *now)
bday->month += 1;
}
}
- printf("(%02u)%.3s-%02u (", (unsigned)bday->month % 12,
+ printf("(%02u)%.3s-%02u (", (unsigned)bday->month,
&"JanFebMarAprMayJunJulAugSepOctNovDec"[3 * ((bday->month - 1) % 12)], (unsigned)bday->day);
when.tm_year = now->tm_year + next_year;
when.tm_mon = (bday->month - 1) % 12;
@@ -97,7 +111,6 @@ print_birthday(struct libcontacts_birthday *bday, const struct tm *now)
days += when.tm_mday - d;
printf("in %i %s)\n", days, days == 1 ? "day" : "days");
}
-
}
int