""" utctime.py - various functions for parsing display UTCTime (c) by Michael Stroeder This module is distributed under the terms of the GPL (GNU GENERAL PUBLIC LICENSE) Version 2 (see http://www.gnu.org/copyleft/gpl.html) $Id: utctime.py,v 1.7 2006/04/24 17:29:48 michael Exp $ """ def strptime(s): """ Parse a UTC time string. """ s = s.split('.')[0] if len(s)>=14: # YYYYmmddHHMMSS year,month,day,hour,minute,second = int(s[0:4]),int(s[4:6]),int(s[6:8]),int(s[8:10]),int(s[10:12]),int(s[12:14]) else: if len(s)==13: # YYmmddHHMMSS year,month,day,hour,minute,second = int(s[0:2]),int(s[2:4]),int(s[4:6]),int(s[6:8]),int(s[8:10]),int(s[10:12]) elif len(s)==11: # YYmmddHHMM year,month,day,hour,minute,second = int(s[0:2]),int(s[2:4]),int(s[4:6]),int(s[6:8]),int(s[8:10]),0 else: raise ValueError,"Time string has invalid length." if year<=50: year=year+2000 else: year=year+1900 return (year,month,day,hour,minute,second,0,1,-1) def strftimeiso8601(t): year,month,day,hour,minute,second,dummy,dummy,dummy = t return '%04d-%02d-%02dT%02d:%02d:%02dZ' % ( t[0],t[1],t[2],t[3],t[4],t[5] )