Commit cd662087 authored by Sriram Karra's avatar Sriram Karra

Move the pythontime format converstion routines to utils.py for wider access.

parent 9cd1504d
##
## Created : Sun Dec 04 19:42:50 IST 2011
## Last Modified : Thu Aug 09 13:44:46 IST 2012
## Last Modified : Mon Apr 08 16:49:22 IST 2013
##
## Copyright (C) 2011, 2012 Sriram Karra <karra.etc@gmail.com>
##
......@@ -32,24 +32,6 @@ from win32com.mapi import mapitags as mt
from win32com.mapi import mapi
import demjson, iso8601, winerror, win32api, pywintypes
def yyyy_mm_dd_to_pytime (date_str):
## FIXME: Temporary hack to ensure we have a yyyy-mm-dd format. Google
## allows the year to be skipped. Outlook crates a problem. We bridge the
## gap by inserting '1887' (birth year of Srinivasa Ramanujan)
res = re.search('--(\d\d)-(\d\d)', date_str)
if res:
date_str = '1887-%s-%s' % (res.group(1), res.group(2))
dt = datetime.strptime(date_str, '%Y-%m-%d')
return pywintypes.Time(dt.timetuple())
def pytime_to_yyyy_mm_dd (pyt):
if pyt.year == 1887:
## Undo the hack noted above.
return ('--%02d-%02d' % (pyt.month, pyt.day))
else:
return ('%04d-%02d-%02d' % (pyt.year, pyt.month, pyt.day))
class OLContactError(Exception):
pass
......@@ -624,13 +606,13 @@ class OLContact(Contact):
d = self._get_olprop(olpd, mt.PR_BIRTHDAY)
if d:
d = utils.utc_time_to_local_ts(d, ret_dt=True)
date = pytime_to_yyyy_mm_dd(d)
date = utils.pytime_to_yyyy_mm_dd(d)
self.set_birthday(date)
a = self._get_olprop(olpd, mt.PR_WEDDING_ANNIVERSARY)
if a:
a = utils.utc_time_to_local_ts(a, ret_dt=True)
date = pytime_to_yyyy_mm_dd(a)
date = utils.pytime_to_yyyy_mm_dd(a)
self.set_anniv(date)
def _snarf_websites_from_olprops (self, olpd):
......@@ -926,12 +908,12 @@ class OLContact(Contact):
bday = self.get_birthday()
if bday:
bday = yyyy_mm_dd_to_pytime(bday)
bday = utils.yyyy_mm_dd_to_pytime(bday)
olprops.append((mt.PR_BIRTHDAY, bday))
anniv = self.get_anniv()
if anniv:
anniv = yyyy_mm_dd_to_pytime(anniv)
anniv = utils.yyyy_mm_dd_to_pytime(anniv)
olprops.append((mt.PR_WEDDING_ANNIVERSARY, anniv))
def _add_websites_to_olprops (self, olprops):
......
##
## Created : Tue Jul 26 06:54:41 IST 2011
## Last Modified : Tue Mar 26 15:55:26 IST 2013
## Last Modified : Mon Apr 08 16:48:20 IST 2013
##
## Copyright (C) 2011, 2012 by Sriram Karra <karra.etc@gmail.com>
## Copyright (C) 2011, 2012, 2013 by Sriram Karra <karra.etc@gmail.com>
##
## This file is part of ASynK
##
......@@ -21,6 +21,25 @@
import iso8601, logging, os, re
def yyyy_mm_dd_to_pytime (date_str):
## FIXME: Temporary hack to ensure we have a yyyy-mm-dd format. Google
## allows the year to be skipped. Outlook crates a problem. We bridge the
## gap by inserting '1887' (birth year of Srinivasa Ramanujan)
res = re.search('--(\d\d)-(\d\d)', date_str)
if res:
date_str = '1887-%s-%s' % (res.group(1), res.group(2))
dt = datetime.strptime(date_str, '%Y-%m-%d')
return pywintypes.Time(dt.timetuple())
def pytime_to_yyyy_mm_dd (pyt):
if pyt.year == 1887:
## Undo the hack noted above.
return ('--%02d-%02d' % (pyt.month, pyt.day))
else:
return ('%04d-%02d-%02d' % (pyt.year, pyt.month, pyt.day))
def asynk_ts_to_iso8601 (ts):
"""The text timestamps in ASynK will be stored in a format that is readily
usable by BBDB. Frequently there is a need to parse it into other formats,
......
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