diff --git a/craft_application/util/cli.py b/craft_application/util/cli.py index 8ee7769a..a56e52ca 100644 --- a/craft_application/util/cli.py +++ b/craft_application/util/cli.py @@ -16,6 +16,7 @@ """CLI-related utilities.""" import datetime +import warnings def format_timestamp(dt: datetime.datetime) -> str: @@ -34,4 +35,9 @@ def format_timestamp(dt: datetime.datetime) -> str: else: # timezone naive, assume it's UTC dtz = dt + warnings.warn( + "Timezone-naive datetime used. Replace with a timezone-aware one if possible.", + category=UserWarning, + stacklevel=2, + ) return dtz.strftime("%Y-%m-%dT%H:%M:%SZ") diff --git a/tests/unit/util/test_cli.py b/tests/unit/util/test_cli.py index a45fb572..d10adb97 100644 --- a/tests/unit/util/test_cli.py +++ b/tests/unit/util/test_cli.py @@ -20,6 +20,12 @@ from craft_application.util import format_timestamp +pytestmark = [ + pytest.mark.filterwarnings( + "ignore:Timezone-naive datetime used. Replace with a timezone-aware one if possible.", + ) +] + @pytest.mark.parametrize( ("dt_obj", "expected"),