-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TimeGenerated in azure log analytics store
Conversion to UTC Always remove the TZ Better millisecond rounding
- Loading branch information
Showing
2 changed files
with
53 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from dateutil import parser | ||
from django.test import SimpleTestCase | ||
from zentral.core.stores.backends.azure_log_analytics import datetime_to_iso8601z_truncated_to_milliseconds | ||
|
||
|
||
class TestDateTimeConverstion(SimpleTestCase): | ||
def _assert_ts_equals(self, ts_list): | ||
for in_ts, out_ts in ts_list: | ||
self.assertEqual( | ||
datetime_to_iso8601z_truncated_to_milliseconds(parser.parse(in_ts)), | ||
out_ts | ||
) | ||
|
||
def test_timezone_conversion(self): | ||
self._assert_ts_equals(( | ||
("2019-01-12T11:11:11.319+02:00", "2019-01-12T09:11:11.319Z"), | ||
("2019-01-12T11:11:11.319+00:00", "2019-01-12T11:11:11.319Z"), | ||
("2019-01-12T11:11:11Z", "2019-01-12T11:11:11Z"), | ||
)) | ||
|
||
def test_microseconds_to_milliseconds(self): | ||
self._assert_ts_equals(( | ||
("2019-01-12T11:11:11.999999", "2019-01-12T11:11:12Z"), | ||
("2019-01-12T11:11:11.123111", "2019-01-12T11:11:11.123Z"), | ||
("2019-01-12T11:11:11.000999+00:00", "2019-01-12T11:11:11.001Z"), | ||
("2019-01-12T11:11:11.000234+00:00", "2019-01-12T11:11:11Z"), | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters