Skip to content

Commit 78b0667

Browse files
add helper method for ms timestamp
1 parent eed74e8 commit 78b0667

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/_incydr_sdk/queries/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ def parse_ts_to_posix_ts(timestamp: Union[str, datetime]):
4040
dt = timestamp if isinstance(timestamp, datetime) else parse_str_to_dt(timestamp)
4141
return dt.timestamp()
4242

43+
def parse_ts_to_ms_ts(timestamp: Union[str, datetime]):
44+
"""
45+
Parse epoch ms timestamp from DATE/DATETIME str or datetime obj.
46+
"""
47+
return parse_ts_to_posix_ts(timestamp) * 1000
4348

4449
def parse_str_to_dt(timestamp: str):
4550
try:

src/_incydr_sdk/sessions/client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from _incydr_sdk.enums.sessions import SessionStates
1010
from _incydr_sdk.enums.sessions import SortKeys
1111
from _incydr_sdk.queries.utils import parse_ts_to_posix_ts
12+
from _incydr_sdk.queries.utils import parse_ts_to_ms_ts
1213
from _incydr_sdk.sessions.models.models import SessionsChangeStateRequest
1314
from _incydr_sdk.sessions.models.models import SessionsCriteriaRequest
1415
from _incydr_sdk.sessions.models.models import SessionsQueryRequest
@@ -76,9 +77,9 @@ def get_page(
7677

7778
# Parse timestamps
7879
if start_time and not isinstance(start_time, (int, float)):
79-
start_time = parse_ts_to_posix_ts(start_time) * 1000
80+
start_time = parse_ts_to_ms_ts(start_time)
8081
if end_time and not isinstance(end_time, (int, float)):
81-
end_time = parse_ts_to_posix_ts(end_time) * 1000
82+
end_time = parse_ts_to_ms_ts(end_time)
8283

8384
if states and not isinstance(states, List):
8485
states = [states]
@@ -253,9 +254,9 @@ def update_state_by_criteria(
253254

254255
# Parse timestamps
255256
if start_time and not isinstance(start_time, (int, float)):
256-
start_time = parse_ts_to_posix_ts(start_time) * 1000
257+
start_time = parse_ts_to_ms_ts(start_time)
257258
if end_time and not isinstance(end_time, (int, float)):
258-
end_time = parse_ts_to_posix_ts(end_time) * 1000
259+
end_time = parse_ts_to_ms_ts(end_time)
259260

260261
if states and not isinstance(states, List):
261262
states = [states]

0 commit comments

Comments
 (0)