Two birthdays with same name
lafrech opened this issue · comments
Imported from https://sourceforge.net/p/gbirthday/bugs/8/
When there are two birthdays with the same name, both are diplayed in the list, but with the same date.
For instance, assuming my CSV file contains the following birthdates:
1979-02-23, Girlfriend
1979-03-08, Girlfriend
(Can't you have two ?...)
then I get the following birthday list;
23 february Girlfriend 15 Days, 33 Years
23 february Girlfriend 29 Days, 33 Years <-- note the mixup here
In fact, "name" is used as a key here, in open_window :
for delta_day in range(self.conf.firstday, self.conf.lastday + 1):
for name in self.addressbook.check_day(delta_day):
add_to_list(delta_day, name, fila)
Maybe using the name as the key was not a good idea. To avoid a complex rework, that function could be patched to check not only the name but also the date (month and day).
For instance:
def add_to_list(delta_day, name, fila):
# search for birthdate
for date, names in self.addressbook.bdays.items():
if name in names:
# Could be someone with the same name,
# check the date is same month and same day
day = datetime.date.today() + datetime.timedelta(delta_day)
if date[5:] == str(day)[5:]:
birthdate = date
break
birthdate = datetime.date(int(birthdate[:4]),
int(birthdate[5:7]),
int(birthdate[8:10]))
I'll try to submit this as a patch.
diff --git a/src/gbirthday/status_icon.py b/src/gbirthday/status_icon.py
index f752737..aac100e 100644
--- a/src/gbirthday/status_icon.py
+++ b/src/gbirthday/status_icon.py
@@ -250,7 +250,13 @@
# search for birthdate
for date, names in self.addressbook.bdays.items():
if name in names:
- birthdate = date
+ # Could be someone with the same name,
+ # check the date is same month and same day
+ day = datetime.date.today() + datetime.timedelta(delta_day)
+ if date[5:] == str(day)[5:]:
+ birthdate = date
+ break
+
birthdate = datetime.date(int(birthdate[:4]),
int(birthdate[5:7]),
int(birthdate[8:10]))
@@ -260,6 +266,7 @@
(2000, birthdate.month, 1, 1, 0, 0, 0, 1, 0)))
except:
lang_month = birthdate.month
+
image = gtk.Image()
day = birthdate.day
years = _('%s Years') % (datetime.date.today().year -
My concern with this patch is that it could lead to a race condition if datetime.today() has changed since bdays_dict was filled. I'm afraid it could trigger a "birthdate used before assignment" error.
I haven't thought about it too long, so I'm really not sure, but perhaps this race condition already existed and just led to a wrong delta days, like "in three days" instead of "in two days". I might be wrong.
A. Bresser: Well, if your girlfriends both have the same name how do you know which one you have to wish a happy birthday?