Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,9 @@ definitions:
items:
type: string
description: |
The possible formats for the cursor field, in order of preference. The first format that matches the cursor field value will be used to parse it. If not provided, the Outgoing Datetime Format will be used.
The possible formats for the cursor field, in order of preference. The first format that matches the cursor field value will be used to parse it.
If none of the specified formats match, the system will attempt to parse the value using robust datetime parsing that handles most ISO8601/RFC3339 compliant formats.
If not provided, the Outgoing Datetime Format will be used as the first attempt.
Use placeholders starting with "%" to describe the format the API is using. The following placeholders are available:
* **%s**: Epoch unix timestamp - `1686218963`
* **%s_as_float**: Epoch unix timestamp in seconds as float with microsecond precision - `1686218963.123456`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from airbyte_cdk.sources.message import MessageRepository
from airbyte_cdk.sources.types import Config, Record, StreamSlice, StreamState
from airbyte_cdk.utils.datetime_helpers import ab_datetime_format, ab_datetime_try_parse
from airbyte_cdk.utils.mapping_helpers import _validate_component_request_option_paths


Expand Down Expand Up @@ -313,6 +314,11 @@ def parse_date(self, date: str) -> datetime.datetime:
return self._parser.parse(date, datetime_format)
except ValueError:
pass

parsed_dt = ab_datetime_try_parse(date)
if parsed_dt:
return parsed_dt

raise ValueError(f"No format in {self.cursor_datetime_formats} matching {date}")

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ def test_given_unknown_format_when_parse_date_then_raise_error():
parameters={},
)
with pytest.raises(ValueError):
slicer.parse_date("2021-01-01T00:00:00.000000+0000")
slicer.parse_date("not-a-valid-datetime-string")


@pytest.mark.parametrize(
Expand Down
Loading