Commit 254a26ba authored by Sriram Karra's avatar Sriram Karra

Refactor the vCard date parsing routine into separate method

parent af9e2fef
......@@ -257,17 +257,11 @@ class CDContact(Contact):
if hasattr(vco, 'bday') and vco.bday.value:
res ='(\d\d\d\d)(\d\d)(\d\d)', vco.bday.value)
if res:
year =
month =
day =
if 'X-APPLE-OMIT-YEAR' in vco.bday.params.keys():
assert(year == vco.bday.params['X-APPLE-OMIT-YEAR'][0])
year = "-"
self.set_birthday('%s-%s-%s' % (year, month, day))
ign = 'X-APPLE-OMIT-YEAR' in vco.bday.params.keys()
bday = self._parse_vcard_date(vco.bday.value, ign)
if bday:
logging.warning('Ignoring unrecognized birthdate (%s) for %s',
vco.bday.value, self.get_disp_name())
......@@ -362,6 +356,24 @@ class CDContact(Contact):
ign = year if year == ignore_year else None
return ign, "%s%s%s" % (year, month, day)
def _parse_vcard_date (self, vd, ign):
"""Takes a vCard date in yyyymmdd format and returns a string
formatted in the BBDB/google contacts date format accounting for
ignored year."""
res ='(\d\d\d\d)(\d\d)(\d\d)', vd)
if res:
year =
month =
day =
if ign:
year = "-"
return "%s-%s-%s" % (year, month, day)
return None
def _add_dates_to_vco (self, vco):
## FIXME: Implement support for creation date, DOB and anniversaries.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment