Skip to content

Commit 31aa51a

Browse files
committed
add docstring and update declarative component schema
1 parent 06778c8 commit 31aa51a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3744,6 +3744,13 @@ interpolation:
37443744
- "{{ format_datetime(config['start_time'], '%Y-%m-%d') }}"
37453745
- "{{ format_datetime(config['start_date'], '%Y-%m-%dT%H:%M:%S.%fZ') }}"
37463746
- "{{ format_datetime(config['start_date'], '%Y-%m-%dT%H:%M:%S.%fZ', '%a, %d %b %Y %H:%M:%S %z') }}"
3747+
- title: str_to_datetime
3748+
description: Converts a string to a datetime object with UTC timezone.
3749+
arguments:
3750+
s: The string to convert.
3751+
return_type: datetime.datetime
3752+
examples:
3753+
- "{{ str_to_datetime('2022-01-14') }}"
37473754
filters:
37483755
- title: hash
37493756
description: Convert the specified value to a hashed string.

airbyte_cdk/sources/declarative/interpolation/macros.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ def timestamp(dt: Union[float, str]) -> Union[int, float]:
6767

6868

6969
def str_to_datetime(s: str) -> datetime.datetime:
70+
"""
71+
Converts a string to a datetime object with UTC timezone
72+
73+
If the input string does not contain timezone information, UTC is assumed.
74+
Supports both basic date strings like "2022-01-14" and datetime strings with optional timezone
75+
like "2022-01-01T13:45:30+00:00".
76+
77+
Usage:
78+
`"{{ str_to_datetime('2022-01-14') }}"`
79+
80+
:param s: string to parse as datetime
81+
:return: datetime object in UTC timezone
82+
"""
83+
7084
parsed_date = parser.isoparse(s)
7185
if not parsed_date.tzinfo:
7286
# Assume UTC if the input does not contain a timezone

0 commit comments

Comments
 (0)