Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions airbyte_cdk/sources/declarative/datetime/datetime_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def parse(self, date: Union[str, int], format: str) -> datetime.datetime:
return datetime.datetime.fromtimestamp(int(date), tz=datetime.timezone.utc)
elif format == "%s_as_float":
return datetime.datetime.fromtimestamp(float(date), tz=datetime.timezone.utc)
elif format == "%epoch_microseconds":
return self._UNIX_EPOCH + datetime.timedelta(microseconds=int(date))
elif format == "%ms":
return self._UNIX_EPOCH + datetime.timedelta(milliseconds=int(date))
elif "%_ms" in format:
Expand All @@ -46,6 +48,8 @@ def format(self, dt: datetime.datetime, format: str) -> str:
return str(int(dt.timestamp()))
if format == "%s_as_float":
return str(float(dt.timestamp()))
if format == "%epoch_microseconds":
return str(int(dt.timestamp() * 1_000_000))
if format == "%ms":
# timstamp() returns a float representing the number of seconds since the unix epoch
return str(int(dt.timestamp() * 1000))
Expand Down
2 changes: 1 addition & 1 deletion airbyte_cdk/sources/declarative/interpolation/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def format_datetime(
)
if format == "%s":
return str(int(dt_datetime.timestamp()))
elif format == "%ms":
elif format == "%epoch_microseconds":
return str(int(dt_datetime.timestamp() * 1_000_000))
return dt_datetime.strftime(format)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_macros_export(test_name, fn_name, found_in_macros):
),
(
"2022-01-01T01:01:01Z",
"%ms",
"%epoch_microseconds",
"%Y-%m-%dT%H:%M:%SZ",
"1640998861000000",
),
Expand Down
Loading