Skip to content

Commit

Permalink
Update datetime parser to allow more datetime type
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssa1303 committed Dec 26, 2024
1 parent f214881 commit e9f17e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions modules/python/kusto/generate_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ def infer_type(value):
pass

# Check if it's a datetime
try:
datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')
return "datetime"
except ValueError:
pass
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

# If none of the above, take it as string
return "string"
Expand Down
2 changes: 2 additions & 0 deletions modules/python/tests/test_generate_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ 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.assertNotEqual(infer_type('abc'), 'datetime')
self.assertNotEqual(infer_type('123'), 'datetime')
self.assertNotEqual(infer_type(123456), 'datetime')
Expand Down

0 comments on commit e9f17e9

Please sign in to comment.