roboluke-tasks/app/utils/datetime.py
Luke Tainton f611b685b3
fix(config): return None if env var is empty or non-existent (#315)
* fix(config): return None if env var is empty or non-existent
* chore: fix pylint issues
* fix: add unit test for non-existent env vars
2024-11-21 22:26:07 +00:00

19 lines
438 B
Python

"""Provides functions for converting timestamps to dates."""
from datetime import datetime
from zoneinfo import ZoneInfo
def timestamp_to_date(timestamp: int) -> str:
"""Convert timestamp to date.
Args:
timestamp (int): Timestamp to convert.
Returns:
str: Date in the format YYYY-MM-DD.
"""
return datetime.fromtimestamp(timestamp=timestamp, tz=ZoneInfo("UTC")).strftime(
"%Y-%m-%d"
)