diff options
author | Ruben Schmidmeister <101409-bash@users.noreply.gitlab.gnome.org> | 2023-01-12 23:16:46 +0000 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2023-01-12 23:16:46 +0000 |
commit | 916f6e658957b9da356f390f5546c3175490929c (patch) | |
tree | e46ddcdca8cb2fba4c61b9245a68c4a6f118c5d2 /src | |
parent | c4ac635f4461f725bc7a5f007e302de73cf24613 (diff) | |
download | gnome-contacts-916f6e658957b9da356f390f5546c3175490929c.tar.gz |
Show leap day birthdays on February 28th in non-leap years
Diffstat (limited to 'src')
-rw-r--r-- | src/contacts-contact-sheet.vala | 5 | ||||
-rw-r--r-- | src/core/contacts-birthday-chunk.vala | 25 |
2 files changed, 26 insertions, 4 deletions
diff --git a/src/contacts-contact-sheet.vala b/src/contacts-contact-sheet.vala index 953da41..b604bdc 100644 --- a/src/contacts-contact-sheet.vala +++ b/src/contacts-contact-sheet.vala @@ -317,11 +317,8 @@ public class Contacts.ContactSheet : Gtk.Widget { // Compare month and date so we can put a reminder string? subtitle = null; - int bd_m, bd_d, now_m, now_d; - birthday_chunk.birthday.to_local ().get_ymd (null, out bd_m, out bd_d); - new DateTime.now_local ().get_ymd (null, out now_m, out now_d); - if (bd_m == now_m && bd_d == now_d) { + if (birthday_chunk.is_today (new DateTime.now_local ())) { subtitle = _("Their birthday is today! 🎉"); } diff --git a/src/core/contacts-birthday-chunk.vala b/src/core/contacts-birthday-chunk.vala index d929dc5..6a87640 100644 --- a/src/core/contacts-birthday-chunk.vala +++ b/src/core/contacts-birthday-chunk.vala @@ -75,4 +75,29 @@ public class Contacts.BirthdayChunk : Chunk { requires (this.persona is BirthdayDetails) { yield ((BirthdayDetails) this.persona).change_birthday (this.birthday); } + + public bool is_today (DateTime now) + requires (this.birthday != null) { + int bd_m, bd_d, now_y, now_m, now_d; + _birthday.to_local().get_ymd (null, out bd_m, out bd_d); + now.get_ymd (out now_y, out now_m, out now_d); + + return (bd_m == now_m && bd_d == now_d) + || (is_leap_day (bd_m, bd_d) && is_birthday_of_leap_day_in_non_leap_year (now_y, now_m, now_d)); + } + + // February 28th is treated as birthday on non-leap years. + // This is consistent with the behaviour of evolution-data-server's Birthdays calendar: + // https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/88 + private bool is_birthday_of_leap_day_in_non_leap_year (int now_y, int now_m, int now_d) { + return now_m == 2 && now_d == 28 && !is_leap_year (now_y); + } + + private bool is_leap_year (int year) { + return ((DateYear) year).is_leap_year (); + } + + private bool is_leap_day (int month, int day) { + return month == 2 && day == 29; + } } |