diff --git a/radicale/utils.py b/radicale/utils.py index 1b5a016c..5c8d4100 100644 --- a/radicale/utils.py +++ b/radicale/utils.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with Radicale. If not, see . +import datetime import os import ssl import sys @@ -46,6 +47,10 @@ ADDRESS_TYPE = Union[Tuple[Union[str, bytes, bytearray], int], Tuple[str, int, int, int]] +# Max YEAR in datetime in unixtime +DATETIME_MAX_UNIXTIME: int = (datetime.MAXYEAR - 1970) * 365 * 24 * 60 * 60 + + def load_plugin(internal_types: Sequence[str], module_name: str, class_name: str, base_class: Type[_T_co], configuration: "config.Configuration") -> _T_co: @@ -244,3 +249,12 @@ def user_groups_as_string(): username = os.getlogin() s = "user=%s" % (username) return s + + +def format_ut(unixtime: int) -> str: + if unixtime < DATETIME_MAX_UNIXTIME: + dt = datetime.datetime.fromtimestamp(unixtime, datetime.UTC) + r = str(unixtime) + "(" + dt.strftime('%Y-%m-%dT%H:%M:%SZ') + ")" + else: + r = str(unixtime) + "(>MAX:" + str(DATETIME_MAX_UNIXTIME) + ")" + return r