]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/: implement `days_since_epoch()`
authorIker Pedrosa <ipedrosa@redhat.com>
Mon, 10 Mar 2025 08:48:26 +0000 (09:48 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 21 May 2025 08:04:42 +0000 (10:04 +0200)
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
tests/system/framework/misc/__init__.py

index 92e0b76b9865417e2df3771d171aca3e9be2e0ee..0ee8a080a59b2fdcfeacf6bedc499ce287a2efe8 100644 (file)
@@ -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