Skip to content

Commit a6e4c2a

Browse files
use DatetimeParser to parse timestamp
1 parent 499e7ce commit a6e4c2a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

airbyte_cdk/sources/declarative/interpolation/macros.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def format_datetime(
172172
return dt.strftime(format)
173173

174174
if isinstance(dt, int):
175-
dt_datetime = datetime.datetime.fromtimestamp(dt, tz=datetime.timezone.utc)
175+
dt_datetime = DatetimeParser().parse(dt, input_format if input_format else "%s")
176176
else:
177177
dt_datetime = (
178178
datetime.datetime.strptime(dt, input_format) if input_format else str_to_datetime(dt)

unit_tests/sources/declarative/interpolation/test_macros.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ def test_macros_export(test_name, fn_name, found_in_macros):
8989
None,
9090
"2023-05-10T14:31:27Z",
9191
),
92+
(
93+
1640998861000000,
94+
"%Y-%m-%dT%H:%M:%SZ",
95+
"%epoch_microseconds",
96+
"2022-01-01T01:01:01Z",
97+
),
98+
(
99+
1640998861000,
100+
"%Y-%m-%dT%H:%M:%SZ",
101+
"%ms",
102+
"2022-01-01T01:01:01Z",
103+
),
92104
],
93105
ids=[
94106
"test_datetime_string_to_date",
@@ -103,6 +115,8 @@ def test_macros_export(test_name, fn_name, found_in_macros):
103115
"test_datetime_string_to_timestamp_in_seconds",
104116
"test_datetime_string_to_timestamp_in_microseconds",
105117
"test_timestamp_to_format_string",
118+
"test_timestamp_epoch_microseconds_to_format_string",
119+
"test_timestamp_ms_to_format_string",
106120
],
107121
)
108122
def test_format_datetime(input_value, format, input_format, expected_output):

0 commit comments

Comments
 (0)