Forum Archive

Person birthday property, error when no year

jrwagz

I have a few contacts in my Contacts app that have birthdays with no year associated. This allows them to show up in the calendar even though I don't know the year.

When I try and access the birthday property on these contacts, I get the following error:

>> person.birthday
Traceback (most recent call last):
File "<string>", line 1, in <module>
ValueError: timestamp out of range for platform time_t

Is there any way to handle this correctly?

omz

Thanks, I wasn't aware of this problem. I don't think there's a workaround, but I'll put this on my todo list.

ccc

Try / Except is your friend...

for person in contacts.get_all_people():
    try:
        birthday = person.birthday
    except ValueError:
        birthday = None
        print(person.full_name + ' has an invalid birthday.')
    if birthday:
        ...