From: Iker Pedrosa Date: Mon, 10 Mar 2025 08:48:26 +0000 (+0100) Subject: tests/: implement `days_since_epoch()` X-Git-Tag: 4.18.0-rc1~92 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=b56fdc329f3deb26a04e54b9e4729fa8116b6bfc;p=thirdparty%2Fshadow.git tests/: implement `days_since_epoch()` Signed-off-by: Iker Pedrosa Reviewed-by: Dan Lavu --- diff --git a/tests/system/framework/misc/__init__.py b/tests/system/framework/misc/__init__.py index 92e0b76b9..0ee8a080a 100644 --- a/tests/system/framework/misc/__init__.py +++ b/tests/system/framework/misc/__init__.py @@ -2,6 +2,7 @@ from __future__ import annotations +import datetime from typing import Any @@ -40,3 +41,14 @@ def to_list_of_strings(value: Any | list[Any] | None) -> list[str]: :rtype: list[str] """ return [str(x) for x in to_list(value)] + + +def days_since_epoch(): + """ + Gets the current date and returns the number of days since 1970-01-01 UTC, this time is also referred to as the + Unix epoch. + """ + epoch = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc) + now_utc = datetime.datetime.now(datetime.timezone.utc) + delta = now_utc - epoch + return delta.days