Skip to content

Commit

Permalink
chore: warn user if datetime is not provided
Browse files Browse the repository at this point in the history
Signed-off-by: Dariusz Duda <dariusz.duda@canonical.com>
  • Loading branch information
dariuszd21 committed Dec 20, 2024
1 parent 3fd9579 commit 70eb7d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions craft_application/util/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""CLI-related utilities."""

import datetime
import warnings


def format_timestamp(dt: datetime.datetime) -> str:
Expand All @@ -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")
6 changes: 6 additions & 0 deletions tests/unit/util/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 70eb7d0

Please sign in to comment.