reviewed consistency of the expiration field in credential, and calls
[sfa.git] / sfa / util / sfatime.py
1 import dateutil.parser
2 import datetime
3
4 from sfa.util.sfalogging import logger
5
6 def utcparse(string):
7     """ Translate a string into a time using dateutil.parser.parse but make sure it's in UTC time and strip
8     the timezone, so that it's compatible with normal datetime.datetime objects"""
9     
10     if isinstance (string, datetime.datetime):
11         logger.warn ("argument to utcparse already a datetime - doing nothing")
12         return string
13     t = dateutil.parser.parse(string)
14     if t.utcoffset() is not None:
15         t = t.utcoffset() + t.replace(tzinfo=None)
16     return t