| Brian Waldon | 6c9f2ec | 2011-11-02 11:40:51 -0400 | [diff] [blame] | 1 | import datetime |
| 2 | |||||
| 3 | |||||
| 4 | #TODO(bcwaldon): expand this to support more iso-compliant formats | ||||
| 5 | ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" | ||||
| 6 | |||||
| 7 | |||||
| 8 | def load_isotime(time_str): | ||||
| 9 | """Convert formatted time stjring to a datetime object.""" | ||||
| 10 | return datetime.datetime.strptime(time_str, ISO_TIME_FORMAT) | ||||
| 11 | |||||
| 12 | |||||
| 13 | def dump_isotime(datetime_obj): | ||||
| 14 | """Format a datetime object as an iso-8601 string.""" | ||||
| 15 | return datetime_obj.strftime(ISO_TIME_FORMAT) | ||||