Skip to content

Commit eddec7b

Browse files
fix: apply ruff formatting to datetime_helpers.py
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent e6db281 commit eddec7b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

airbyte_cdk/utils/datetime_helpers.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ def ab_datetime_now() -> AirbyteDateTime:
358358
return AirbyteDateTime.from_datetime(datetime.now(timezone.utc))
359359

360360

361-
def ab_datetime_parse(dt_str: str | int, formats: list[str] | None = None, disallow_other_formats: bool = False) -> AirbyteDateTime:
361+
def ab_datetime_parse(
362+
dt_str: str | int, formats: list[str] | None = None, disallow_other_formats: bool = False
363+
) -> AirbyteDateTime:
362364
"""Parses a datetime string or timestamp into an AirbyteDateTime with timezone awareness.
363365
364366
This implementation is as flexible as possible to handle various datetime formats.
@@ -423,10 +425,11 @@ def ab_datetime_parse(dt_str: str | int, formats: list[str] | None = None, disal
423425
return AirbyteDateTime.from_datetime(parsed)
424426
except ValueError:
425427
continue
426-
427-
if disallow_other_formats:
428-
raise ValueError(f"Could not parse datetime string '{dt_str}' with any of the provided formats: {formats}")
429428

429+
if disallow_other_formats:
430+
raise ValueError(
431+
f"Could not parse datetime string '{dt_str}' with any of the provided formats: {formats}"
432+
)
430433

431434
# Handle date-only format first
432435
if ":" not in dt_str and dt_str.count("-") == 2 and "/" not in dt_str:
@@ -462,7 +465,9 @@ def ab_datetime_parse(dt_str: str | int, formats: list[str] | None = None, disal
462465
raise ValueError(f"Could not parse datetime string: {dt_str}")
463466

464467

465-
def ab_datetime_try_parse(dt_str: str | int, formats: list[str] | None = None, disallow_other_formats: bool = False) -> AirbyteDateTime | None:
468+
def ab_datetime_try_parse(
469+
dt_str: str | int, formats: list[str] | None = None, disallow_other_formats: bool = False
470+
) -> AirbyteDateTime | None:
466471
"""Try to parse the input as a datetime, failing gracefully instead of raising an exception.
467472
468473
This is a thin wrapper around `ab_datetime_parse()` that catches parsing errors and
@@ -485,7 +490,9 @@ def ab_datetime_try_parse(dt_str: str | int, formats: list[str] | None = None, d
485490
>>> ab_datetime_try_parse("2023-03-14 15:09:26", formats=["%Y-%m-%d %H:%M:%S"]) # Using specific format
486491
"""
487492
try:
488-
return ab_datetime_parse(dt_str, formats=formats, disallow_other_formats=disallow_other_formats)
493+
return ab_datetime_parse(
494+
dt_str, formats=formats, disallow_other_formats=disallow_other_formats
495+
)
489496
except (ValueError, TypeError):
490497
return None
491498

0 commit comments

Comments
 (0)