Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use different library for timestamp parser #455

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading