NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

Changeset 333

Show
Ignore:
Timestamp:
04/29/10 09:57:52
Author:
haines
Message:

fix scanf_datetime() in procutil module to handle meaningless dates

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • raw2proc/trunk/raw2proc/procutil.py

    r320 r333  
    11#!/usr/bin/env python 
    2 # Last modified:  Time-stamp: <2010-04-07 17:41:26 haines> 
     2# Last modified:  Time-stamp: <2010-04-29 09:44:03 haines> 
    33"""Utilities to help data processing  
    44 
    55   Mostly time functions right now 
    66 
    7    TO DO: 
    8    check_configs() 
    9    unit conversions (udunits?) 
    107""" 
    118 
     
    122119    # default string format follows convention YYYY-MM-DDThh:mm:ss 
    123120     
    124     t = time.strptime(ts, fmt) 
    125     # the '*' operator unpacks the tuple, producing the argument list. 
    126     dt = datetime(*t[0:6]) 
     121    try: 
     122        t = time.strptime(ts, fmt) 
     123        # the '*' operator unpacks the tuple, producing the argument list. 
     124        dt = datetime(*t[0:6]) 
     125    except ValueError, e: 
     126        # value error if something not valid for datetime 
     127        # e.g. month 1...12, something parsed wrong 
     128        dt = None 
     129    else: 
     130        # absolute difference in days from now (UTC) 
     131        z = dt - datetime.utcnow() 
     132        daysdiff = abs(z.days) 
     133        # if this date unreasonable (>10 years*365), throw it out 
     134        # something parsed wrong 
     135        if daysdiff > 3650: 
     136            dt = None                 
     137 
    127138    return dt 
    128139