Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Aug 20, 2024
1 parent 148dec7 commit cf69c20
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion singer_sdk/streams/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,23 @@ def _write_replication_key_signpost(
state = self.get_context_state(context)
write_replication_key_signpost(state, value)

def _parse_datetime(self, value: str) -> datetime.datetime: # noqa: PLR6301
"""Parse a datetime string.
Args:
value: The datetime string.
Returns:
The parsed datetime, timezone-aware preferred.
"""
result = datetime_fromisoformat(value)

# Ensure datetime is timezone-aware
if not result.tzinfo:
result = result.astimezone()

return result

def compare_start_date(self, value: str, start_date_value: str) -> str:
"""Compare a bookmark value to a start date and return the most recent value.
Expand All @@ -384,7 +401,7 @@ def compare_start_date(self, value: str, start_date_value: str) -> str:
The most recent value between the bookmark and start date.
"""
if self.is_timestamp_replication_key:
return max(value, start_date_value, key=datetime_fromisoformat)
return max(value, start_date_value, key=self._parse_datetime)

return value

Expand Down

0 comments on commit cf69c20

Please sign in to comment.