Index: raw2proc/trunk/raw2proc/procutil.py =================================================================== --- raw2proc/trunk/raw2proc/procutil.py (revision 320) +++ raw2proc/trunk/raw2proc/procutil.py (revision 333) @@ -1,11 +1,8 @@ #!/usr/bin/env python -# Last modified: Time-stamp: <2010-04-07 17:41:26 haines> +# Last modified: Time-stamp: <2010-04-29 09:44:03 haines> """Utilities to help data processing Mostly time functions right now - TO DO: - check_configs() - unit conversions (udunits?) """ @@ -122,7 +119,21 @@ # default string format follows convention YYYY-MM-DDThh:mm:ss - t = time.strptime(ts, fmt) - # the '*' operator unpacks the tuple, producing the argument list. - dt = datetime(*t[0:6]) + try: + t = time.strptime(ts, fmt) + # the '*' operator unpacks the tuple, producing the argument list. + dt = datetime(*t[0:6]) + except ValueError, e: + # value error if something not valid for datetime + # e.g. month 1...12, something parsed wrong + dt = None + else: + # absolute difference in days from now (UTC) + z = dt - datetime.utcnow() + daysdiff = abs(z.days) + # if this date unreasonable (>10 years*365), throw it out + # something parsed wrong + if daysdiff > 3650: + dt = None + return dt