From 0676afbd7191be6b9d971670497ccd4c5f48ee33 Mon Sep 17 00:00:00 2001 From: Chan-Ho Suh Date: Mon, 25 Sep 2023 16:42:11 -0400 Subject: [PATCH] Expand docstrings --- curvesim/utils/datetime.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/curvesim/utils/datetime.py b/curvesim/utils/datetime.py index 860742bdc..baf9e575f 100644 --- a/curvesim/utils/datetime.py +++ b/curvesim/utils/datetime.py @@ -1,10 +1,25 @@ +""" +Utility functions for working with datetimes in UTC format. + +This module provides custom versions of common datetime operations to ensure +returned datetimes are always in the UTC timezone and are not naive. + +The main goal is to prevent potential issues related to timezone-aware and +timezone-naive datetime objects. +""" from datetime import datetime, timezone -def now(): +def now() -> datetime: """ Customized version of `datetime.datetime.now` to ensure UTC timezone and format. + + Returns + ------- + datetime + Current UTC datetime with hour, minute, second, and microsecond set to 0. + This datetime is timezone-aware and is not naive. """ utc_dt = datetime.now(timezone.utc).replace( hour=0, minute=0, second=0, microsecond=0 @@ -12,10 +27,21 @@ def now(): return utc_dt -def fromtimestamp(timestamp): +def fromtimestamp(timestamp: int) -> datetime: """ Customized version of `datetime.datetime.fromtimestamp` to ensure UTC timezone and format. + + Parameters + ---------- + timestamp : int + Unix timestamp to be converted to datetime. + + Returns + ------- + datetime + The UTC datetime representation of the given timestamp. + This datetime is timezone-aware and is not naive. """ utc_timestamp = datetime.fromtimestamp(timestamp, tz=timezone.utc) return utc_timestamp