File tree Expand file tree Collapse file tree 3 files changed +12
-10
lines changed
Expand file tree Collapse file tree 3 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -448,16 +448,15 @@ def convert_to_datetime(self, ts):
448448 else datetime .strptime (ts , given_format )
449449 )
450450
451+ def is_unix_ts (self , time ) -> bool :
452+ return isinstance (time , (int , float ))
453+
451454 def get_time_format (self , time ) -> Optional [str ]:
452455 if self .is_datetime_obj (time ):
453456 return "datetimeobj"
454457
455- try :
456- # Try unix timestamp in seconds.
457- datetime .fromtimestamp (float (time ))
458+ if self .is_unix_ts (time ):
458459 return "unixtimestamp"
459- except ValueError :
460- pass
461460
462461 for time_format in self .time_formats :
463462 try :
Original file line number Diff line number Diff line change @@ -135,12 +135,15 @@ def get_private_client_ips(
135135 private_clients .append (ip )
136136 return private_clients
137137
138- def convert_starttime_to_epoch (self , starttime ) -> str :
138+ def convert_starttime_to_unix_ts (self , starttime ) -> str :
139+ if utils .is_unix_ts (starttime ):
140+ return starttime
141+
139142 try :
140143 return utils .convert_ts_format (starttime , "unixtimestamp" )
141144 except ValueError :
142145 self .print (
143- f"We can not recognize time format of "
146+ f"Slips can not recognize time format of "
144147 f"flow.starttime: { starttime } " ,
145148 0 ,
146149 1 ,
@@ -537,7 +540,7 @@ def add_flow_to_profile(self, flow):
537540 self .print (f"Storing data in the profile: { profileid } " , 3 , 0 )
538541
539542 n = time .time ()
540- flow .starttime = self .convert_starttime_to_epoch (flow .starttime )
543+ flow .starttime = self .convert_starttime_to_unix_ts (flow .starttime )
541544 time_it_Took = time .time () - n
542545
543546 self .log_time ("convert_starttime_to_epoch" , time_it_Took )
Original file line number Diff line number Diff line change @@ -199,7 +199,7 @@ def test_convert_starttime_to_epoch():
199199 ) as mock_convert_ts_format :
200200 mock_convert_ts_format .return_value = 1680604800
201201
202- converted = profiler .convert_starttime_to_epoch (starttime )
202+ converted = profiler .convert_starttime_to_unix_ts (starttime )
203203
204204 mock_convert_ts_format .assert_called_once_with (
205205 "2023-04-04 12:00:00" , "unixtimestamp"
@@ -214,7 +214,7 @@ def test_convert_starttime_to_epoch_invalid_format(monkeypatch):
214214 "slips_files.core.profiler.utils.convert_ts_format" ,
215215 Mock (side_effect = ValueError ),
216216 )
217- converted = profiler .convert_starttime_to_epoch (starttime )
217+ converted = profiler .convert_starttime_to_unix_ts (starttime )
218218 assert converted == "not a real time"
219219
220220
You can’t perform that action at this time.
0 commit comments