4 _strf = "%Y%m%d%H%M%S%f"
5 _reabs = re.compile("^\d{20}$")
6 _rerel = re.compile("^(?P<time>\d+(.\d+)?)(?P<units>h|m|s|ms|us)$")
8 # Work around to fix "ImportError: Failed to import _strptime because the import lock is held by another thread."
9 datetime.datetime.strptime("20120807124732894211", _strf)
13 return datetime.datetime.now().strftime(_strf)
15 def strfdiff(str1, str2):
16 # Time difference in seconds without ignoring miliseconds
17 d1 = datetime.datetime.strptime(str1, _strf)
18 d2 = datetime.datetime.strptime(str2, _strf)
20 ddays = diff.days * 86400
21 dus = round(diff.microseconds * 1.0e-06, 2)
22 ret = ddays + diff.seconds + dus
27 """ User defined date to scheduler date """
30 if _reabs.match(date):
32 m = _rerel.match(date)
34 time = float(m.groupdict()['time'])
35 units = m.groupdict()['units']
37 delta = datetime.timedelta(hours = time)
39 delta = datetime.timedelta(minutes = time)
41 delta = datetime.timedelta(seconds = time)
43 delta = datetime.timedelta(microseconds = (time*1000))
45 delta = datetime.timedelta(microseconds = time)
46 now = datetime.datetime.now()
48 return d.strftime(_strf)