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 | |
---|