зеркало из https://github.com/mozilla/MozDef.git
Merge pull request #661 from mozilla/improve_toutc_function
Improve toutc function to handle negative values
This commit is contained in:
Коммит
18504dca50
|
@ -25,7 +25,11 @@ def toUTC(suspectedDate):
|
|||
epochDivisor = int(str(1) + '0'*(len(str(suspectedDate)) % 10))
|
||||
objDate = datetime.fromtimestamp(float(suspectedDate/epochDivisor), LOCAL_TIMEZONE)
|
||||
elif type(suspectedDate) in (str, unicode):
|
||||
objDate = parse(suspectedDate, fuzzy=True)
|
||||
if suspectedDate[0] == '-':
|
||||
# Negative number, so let's pick a date for them
|
||||
objDate = datetime(1970, 1, 1)
|
||||
else:
|
||||
objDate = parse(suspectedDate, fuzzy=True)
|
||||
try:
|
||||
if objDate.tzinfo is None:
|
||||
objDate=LOCAL_TIMEZONE.localize(objDate)
|
||||
|
|
|
@ -89,3 +89,13 @@ class TestToUTC():
|
|||
result = toUTC(1.468443523e+11)
|
||||
self.result_is_datetime(result)
|
||||
assert str(result) == '2016-07-13 20:58:43+00:00'
|
||||
|
||||
def test_negative_string_float(self):
|
||||
result = toUTC("-86400.000000")
|
||||
self.result_is_datetime(result)
|
||||
assert str(result) == '1970-01-01 00:00:00+00:00'
|
||||
|
||||
def test_negative_string_int(self):
|
||||
result = toUTC("-12345")
|
||||
self.result_is_datetime(result)
|
||||
assert str(result) == '1970-01-01 00:00:00+00:00'
|
||||
|
|
Загрузка…
Ссылка в новой задаче