Skip to content

Commit 844a1a8

Browse files
committed
make str_to_datetime a public macro
1 parent 337d8c5 commit 844a1a8

File tree

9 files changed

+15
-12
lines changed

9 files changed

+15
-12
lines changed

airbyte_cdk/sources/declarative/interpolation/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
2+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
33
#
44

55
from airbyte_cdk.sources.declarative.interpolation.interpolated_boolean import InterpolatedBoolean

airbyte_cdk/sources/declarative/interpolation/filters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#
2-
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
2+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
33
#
4+
45
import base64
56
import hashlib
67
import json

airbyte_cdk/sources/declarative/interpolation/interpolated_boolean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
2+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
33
#
44

55
from dataclasses import InitVar, dataclass

airbyte_cdk/sources/declarative/interpolation/interpolated_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
2+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
33
#
44

55

airbyte_cdk/sources/declarative/interpolation/interpolated_nested_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
2+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
33
#
44

55

airbyte_cdk/sources/declarative/interpolation/interpolated_string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
2+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
33
#
44

55
from dataclasses import InitVar, dataclass

airbyte_cdk/sources/declarative/interpolation/interpolation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#
2-
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
2+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
33
#
44

5+
56
from abc import ABC, abstractmethod
67
from typing import Any, Optional
78

airbyte_cdk/sources/declarative/interpolation/jinja.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
2+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
33
#
44

55
import ast

airbyte_cdk/sources/declarative/interpolation/macros.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
2+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
33
#
44

55
import builtins
@@ -63,10 +63,10 @@ def timestamp(dt: Union[float, str]) -> Union[int, float]:
6363
if isinstance(dt, (int, float)):
6464
return int(dt)
6565
else:
66-
return _str_to_datetime(dt).astimezone(pytz.utc).timestamp()
66+
return str_to_datetime(dt).astimezone(pytz.utc).timestamp()
6767

6868

69-
def _str_to_datetime(s: str) -> datetime.datetime:
69+
def str_to_datetime(s: str) -> datetime.datetime:
7070
parsed_date = parser.isoparse(s)
7171
if not parsed_date.tzinfo:
7272
# Assume UTC if the input does not contain a timezone
@@ -155,7 +155,7 @@ def format_datetime(
155155
if isinstance(dt, datetime.datetime):
156156
return dt.strftime(format)
157157
dt_datetime = (
158-
datetime.datetime.strptime(dt, input_format) if input_format else _str_to_datetime(dt)
158+
datetime.datetime.strptime(dt, input_format) if input_format else str_to_datetime(dt)
159159
)
160160
if format == "%s":
161161
return str(int(dt_datetime.timestamp()))
@@ -172,5 +172,6 @@ def format_datetime(
172172
duration,
173173
format_datetime,
174174
today_with_timezone,
175+
str_to_datetime,
175176
]
176177
macros = {f.__name__: f for f in _macros_list}

0 commit comments

Comments
 (0)