Contact info

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
jurkov
Posts: 8
Joined: 07 Jul 2016 20:06

Contact info

Post by jurkov » 19 Nov 2016 14:22

Hello there.
I want to make a custom widget with info about how many days remain to day when someone celebrate a birthday. It is possible to find out this info from Contacts?
Thanks. Juraj.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Contact info

Post by Martin » 20 Nov 2016 13:40

Hi,

There's no built-in action to query this information in a comfortable way so you have to use action Query Content Provider:
Content URI: content://comn.android.contacts/data
Projection: data1
Selection: display_name like 'NameXYZ%' and mimetype like '%event'
Result Type: Single value
Variable: birthdate

The date is provided as a text in format yyyy-MM-dd so you have to use a script to calculate the number of days to go. Following should work in an action Script:

Code: Select all

// adjust text to reflect birthday in current year, otherwise leap year might have negative effect
birthdate = "{trigertime,dateformat,yyyy}-"+substring(birthdate, 5);

// convert from text to a proper date object
date = getDate(birthdate, "yyyy-MM-dd");

// calculate the day number of birthday in this year
day_of_year = "{date,dateformat,D}";

// calculate todays day number
day_of_year_today = "{triggertime,dateformat,D}";

// calculate the day difference
diff = day_of_year - day_of_year_today;
Alternatively querying the contacts-calendar with condition Calendar Event could also work:
Starting: 30d before
Calendars: Google:Contacts
Event Type: All day events
Multiple events: Prefer the first

The start of the event will become available in variable event_start, title in variable event_title.

You still have to calculate the days to go using a script like the one shown above.

Regards,
Martin

Post Reply