Skip to content

Commit

Permalink
DatetimeParser: ref to use datetimeparser
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Inzhyyants <[email protected]>
  • Loading branch information
artem1205 committed Dec 23, 2024
1 parent 8b3d2f7 commit 1ed0071
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion airbyte_cdk/sources/declarative/datetime/datetime_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import datetime
from typing import Union

import dateparser


class DatetimeParser:
"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1ed0071

Please sign in to comment.