diff --git a/external-worker/flowable/external_worker_client/utils.py b/external-worker/flowable/external_worker_client/utils.py index 2646320..ad90680 100644 --- a/external-worker/flowable/external_worker_client/utils.py +++ b/external-worker/flowable/external_worker_client/utils.py @@ -1,4 +1,7 @@ from datetime import datetime def parse_date_time(date): - return datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ") if date is not None else None + try: + return datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ") if date is not None else None + except ValueError: + return datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ") if date is not None else None \ No newline at end of file diff --git a/external-worker/tests/test_utils.py b/external-worker/tests/test_utils.py new file mode 100644 index 0000000..b205684 --- /dev/null +++ b/external-worker/tests/test_utils.py @@ -0,0 +1,15 @@ +import datetime +import unittest + +from flowable.external_worker_client.utils import parse_date_time + + +class TestUtils(unittest.TestCase): + + def test_parse_date_time_with_millis(self): + date = parse_date_time('2024-09-23T15:23:08.123Z') + self.assertEqual(datetime.datetime(2024, 9, 23, 15, 23, 8, 123000), date) + + def test_parse_date_time_without_millis(self): + date = parse_date_time('2024-09-23T15:23:08Z') + self.assertEqual(datetime.datetime(2024, 9, 23, 15, 23, 8, 0), date)