From 1ed0071295731e63366db271dc26727b3de1f832 Mon Sep 17 00:00:00 2001 From: Artem Inzhyyants Date: Mon, 23 Dec 2024 15:51:27 +0100 Subject: [PATCH] DatetimeParser: ref to use datetimeparser Signed-off-by: Artem Inzhyyants --- .../sources/declarative/datetime/datetime_parser.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/airbyte_cdk/sources/declarative/datetime/datetime_parser.py b/airbyte_cdk/sources/declarative/datetime/datetime_parser.py index 93122e29c..1ecb4638d 100644 --- a/airbyte_cdk/sources/declarative/datetime/datetime_parser.py +++ b/airbyte_cdk/sources/declarative/datetime/datetime_parser.py @@ -5,6 +5,8 @@ import datetime from typing import Union +import dateparser + class DatetimeParser: """ @@ -32,7 +34,15 @@ def parse(self, date: Union[str, int], format: str) -> datetime.datetime: elif format == "%ms": return self._UNIX_EPOCH + datetime.timedelta(milliseconds=int(date)) - parsed_datetime = datetime.datetime.strptime(str(date), format) + parsed_datetime = dateparser.parse( + str(date), + date_formats=[format], + settings={ + "TIMEZONE": "UTC", + "RETURN_AS_TIMEZONE_AWARE": True, + }, + ) + if self._is_naive(parsed_datetime): return parsed_datetime.replace(tzinfo=datetime.timezone.utc) return parsed_datetime