Skip to content

Commit

Permalink
Use different library for timestamp parser (#455)
Browse files Browse the repository at this point in the history
Use a different library which can handle different timestamp formats
better.
  • Loading branch information
alyssa1303 authored Dec 27, 2024
1 parent ff8ea16 commit 83f93d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions modules/python/kusto/generate_commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from datetime import datetime
from dateutil.parser import isoparse
import sys
import base64

Expand Down Expand Up @@ -34,13 +34,12 @@ def infer_type(value):
except (json.JSONDecodeError, TypeError):
pass

# Check if it's a datetime
for fmt in ('%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%dT%H:%M:%S.%f'):
try:
datetime.strptime(value, fmt)
return "datetime"
except ValueError:
pass
# Check if it's a datetime
try:
isoparse(value)
return "datetime"
except ValueError:
pass

# If none of the above, take it as string
return "string"
Expand Down
2 changes: 1 addition & 1 deletion modules/python/tests/test_generate_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_infer_dynamic(self):
def test_infer_datetime(self):
self.assertEqual(infer_type('2022-01-01T12:00:00Z'), 'datetime')
self.assertEqual(infer_type('2024-12-26T12:14:50.637517'), 'datetime')
self.assertNotEqual(infer_type('2024-12-26T15:02:17.681161609Z'), 'datetime')
self.assertEqual(infer_type('2024-12-26T15:02:17.681161609Z'), 'datetime')
self.assertNotEqual(infer_type('abc'), 'datetime')
self.assertNotEqual(infer_type('123'), 'datetime')
self.assertNotEqual(infer_type(123456), 'datetime')
Expand Down

0 comments on commit 83f93d7

Please sign in to comment.