diff --git a/modules/python/kusto/generate_commands.py b/modules/python/kusto/generate_commands.py index ce5a78127..6259e5ceb 100644 --- a/modules/python/kusto/generate_commands.py +++ b/modules/python/kusto/generate_commands.py @@ -1,5 +1,5 @@ import json -from datetime import datetime +from dateutil.parser import isoparse import sys import base64 @@ -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" diff --git a/modules/python/tests/test_generate_commands.py b/modules/python/tests/test_generate_commands.py index 3e4da93b6..a5cdc7e69 100644 --- a/modules/python/tests/test_generate_commands.py +++ b/modules/python/tests/test_generate_commands.py @@ -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')