...
|
...
|
@@ -16,6 +16,7 @@ import base64
|
16
|
16
|
import errno
|
17
|
17
|
import urllib
|
18
|
18
|
import dateutil.parser
|
|
19
|
+from calendar import timegm
|
19
|
20
|
|
20
|
21
|
from logging import debug, info, warning, error
|
21
|
22
|
|
...
|
...
|
@@ -136,22 +137,20 @@ __all__.append("appendXmlTextNode")
|
136
|
136
|
def dateS3toPython(date):
|
137
|
137
|
# Reset milliseconds to 000
|
138
|
138
|
date = re.compile('\.[0-9]*(?:[Z\\-\\+]*?)').sub(".000", date)
|
139
|
|
- return dateutil.parser.parse(date, fuzzy=True).timetuple()
|
|
139
|
+ return dateutil.parser.parse(date, fuzzy=True)
|
140
|
140
|
__all__.append("dateS3toPython")
|
141
|
141
|
|
142
|
142
|
def dateS3toUnix(date):
|
143
|
|
- ## FIXME: This should be timezone-aware.
|
144
|
|
- ## Currently the argument to strptime() is GMT but mktime()
|
145
|
|
- ## treats it as "localtime". Anyway...
|
146
|
|
- return time.mktime(dateS3toPython(date))
|
|
143
|
+ ## NOTE: This is timezone-aware and return the timestamp regarding GMT
|
|
144
|
+ return timegm(dateS3toPython(date).utctimetuple())
|
147
|
145
|
__all__.append("dateS3toUnix")
|
148
|
146
|
|
149
|
147
|
def dateRFC822toPython(date):
|
150
|
|
- return rfc822.parsedate(date)
|
|
148
|
+ return dateutil.parser.parse(date, fuzzy=True)
|
151
|
149
|
__all__.append("dateRFC822toPython")
|
152
|
150
|
|
153
|
151
|
def dateRFC822toUnix(date):
|
154
|
|
- return time.mktime(dateRFC822toPython(date))
|
|
152
|
+ return timegm(dateRFC822toPython(date).utctimetuple())
|
155
|
153
|
__all__.append("dateRFC822toUnix")
|
156
|
154
|
|
157
|
155
|
def formatSize(size, human_readable = False, floating_point = False):
|
...
|
...
|
@@ -168,20 +167,8 @@ def formatSize(size, human_readable = False, floating_point = False):
|
168
|
168
|
__all__.append("formatSize")
|
169
|
169
|
|
170
|
170
|
def formatDateTime(s3timestamp):
|
171
|
|
- try:
|
172
|
|
- import pytz
|
173
|
|
- timezone = pytz.timezone(os.environ.get('TZ', 'UTC'))
|
174
|
|
- tz = pytz.timezone('UTC')
|
175
|
|
- ## Can't unpack args and follow that with kwargs in python 2.5
|
176
|
|
- ## So we pass them all as kwargs
|
177
|
|
- params = zip(('year', 'month', 'day', 'hour', 'minute', 'second', 'tzinfo'),
|
178
|
|
- dateS3toPython(s3timestamp)[0:6] + (tz,))
|
179
|
|
- params = dict(params)
|
180
|
|
- utc_dt = datetime.datetime(**params)
|
181
|
|
- dt_object = utc_dt.astimezone(timezone)
|
182
|
|
- except ImportError:
|
183
|
|
- dt_object = datetime.datetime(*dateS3toPython(s3timestamp)[0:6])
|
184
|
|
- return dt_object.strftime("%Y-%m-%d %H:%M")
|
|
171
|
+ date_obj = dateutil.parser.parse(s3timestamp, fuzzy=True)
|
|
172
|
+ return date_obj.strftime("%Y-%m-%d %H:%M")
|
185
|
173
|
__all__.append("formatDateTime")
|
186
|
174
|
|
187
|
175
|
def convertTupleListToDict(list):
|