Skip to content

Commit 50bf5a5

Browse files
authored
Format datetime as UTC (#44)
IR-774
1 parent 765dcbb commit 50bf5a5

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

api_client/python/timesketch_api_client/search.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919

2020
import pandas
2121

22-
from . import error
23-
from . import resource
24-
from . import searchtemplate
25-
22+
from . import error, resource, searchtemplate
2623

2724
logger = logging.getLogger("timesketch_api.search")
2825

@@ -1129,18 +1126,10 @@ def to_pandas(self):
11291126
return_list.append(source)
11301127

11311128
data_frame = pandas.DataFrame(return_list)
1132-
if "datetime" in data_frame:
1133-
try:
1134-
data_frame["datetime"] = pandas.to_datetime(data_frame.datetime)
1135-
except pandas.errors.OutOfBoundsDatetime:
1136-
pass
1137-
elif "timestamp" in data_frame:
1138-
try:
1139-
data_frame["datetime"] = pandas.to_datetime(
1140-
data_frame.timestamp / 1e6, utc=True, unit="s"
1141-
)
1142-
except pandas.errors.OutOfBoundsDatetime:
1143-
pass
1129+
try:
1130+
data_frame["datetime"] = pandas.to_datetime(data_frame.datetime, utc=True)
1131+
except pandas.errors.OutOfBoundsDatetime:
1132+
pass
11441133

11451134
return data_frame
11461135

api_client/python/timesketch_api_client/sketch.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,6 @@ def explore(
10341034
RuntimeError: if the query is missing needed values, or if the
10351035
sketch is archived.
10361036
"""
1037-
logger.warning(
1038-
"Using this function is discouraged, please consider using "
1039-
"the search.Search object instead, which is more flexible."
1040-
)
10411037

10421038
if not (query_string or query_filter or query_dsl or view):
10431039
raise RuntimeError("You need to supply a query or view")

api_client/python/timesketch_api_client/test_lib.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,13 @@ def json(self):
215215
},
216216
"objects": [
217217
{
218-
"id": 1,
219-
"name": "test",
220-
"searchindex": {"id": 1234, "index_name": "test"},
218+
"_id": 1234,
219+
"_index": "test",
220+
"_source": {
221+
"datetime": "2012-03-14T08:12:03.998281",
222+
"id": 1,
223+
"name": "test",
224+
},
221225
}
222226
],
223227
}
@@ -228,9 +232,13 @@ def json(self):
228232
},
229233
"objects": [
230234
{
231-
"id": 2,
232-
"name": "more_test",
233-
"searchindex": {"id": 42, "index_name": "even_more_test"},
235+
"_id": 42,
236+
"_index": "even_more_test",
237+
"_source": {
238+
"datetime": "2012-03-14T08:12:03.998281",
239+
"id": 2,
240+
"name": "more_test",
241+
},
234242
}
235243
],
236244
}

0 commit comments

Comments
 (0)