diff options
author | Chris Ball <cjb@laptop.org> | 2009-07-13 11:45:40 -0400 |
---|---|---|
committer | Chris Ball <cjb@laptop.org> | 2009-07-13 11:45:40 -0400 |
commit | 5e249abfee7273c79640c4211607a6b4bf7b374c (patch) | |
tree | d588c5c801e142b59af53b9f9c15e3f9e1982737 /libbe/utility.py | |
parent | 64f62aa2bb841c483e8cb2b663434b3ad3038f4c (diff) | |
parent | 17adbfb1c04684b986bf2c97cc4fa5197198aadc (diff) | |
download | bugseverywhere-5e249abfee7273c79640c4211607a6b4bf7b374c.tar.gz |
Large merge from W. Trevor King. Highlights:
be show --only-raw-body
be-mbox-to-xml
be-xml-to-mbox
be comment --xml
be --dir
Diffstat (limited to 'libbe/utility.py')
-rw-r--r-- | libbe/utility.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/libbe/utility.py b/libbe/utility.py index 8a0f318..e16b94a 100644 --- a/libbe/utility.py +++ b/libbe/utility.py @@ -1,6 +1,5 @@ # Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc. # W. Trevor King <wking@drexel.edu> -# <abentley@panoramicfeedback.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,6 +20,7 @@ import os import shutil import tempfile import time +import types import doctest @@ -77,17 +77,34 @@ def time_to_str(time_val): return time.strftime(RFC_2822_TIME_FMT, time.gmtime(time_val)) def str_to_time(str_time): - """Convert an RFC 2822-fomatted string into a time falue. + """Convert an RFC 2822-fomatted string into a time value. >>> str_to_time("Thu, 01 Jan 1970 00:00:00 +0000") 0 >>> q = time.time() >>> str_to_time(time_to_str(q)) == int(q) True + >>> str_to_time("Thu, 01 Jan 1970 00:00:00 -1000") + 36000 """ - return calendar.timegm(time.strptime(str_time, RFC_2822_TIME_FMT)) + timezone_str = str_time[-5:] + if timezone_str != "+0000": + str_time = str_time.replace(timezone_str, "+0000") + time_val = calendar.timegm(time.strptime(str_time, RFC_2822_TIME_FMT)) + timesign = -int(timezone_str[0]+"1") # "+" -> time_val ahead of GMT + timezone_tuple = time.strptime(timezone_str[1:], "%H%M") + timezone = timezone_tuple.tm_hour*3600 + timezone_tuple.tm_min*60 + return time_val + timesign*timezone def handy_time(time_val): return time.strftime("%a, %d %b %Y %H:%M", time.localtime(time_val)) +def time_to_gmtime(str_time): + """Convert an RFC 2822-fomatted string to a GMT string. + >>> time_to_gmtime("Thu, 01 Jan 1970 00:00:00 -1000") + 'Thu, 01 Jan 1970 10:00:00 +0000' + """ + time_val = str_to_time(str_time) + return time_to_str(time_val) + suite = doctest.DocTestSuite() |