From 00f7bc872a943726a6b40779d6e005aa10c718dc Mon Sep 17 00:00:00 2001
From: David Trattnig <david.trattnig@o94.at>
Date: Wed, 19 Feb 2020 14:46:11 +0100
Subject: [PATCH] Initial commit.

---
 modules/base/simpleutil.py | 70 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 modules/base/simpleutil.py

diff --git a/modules/base/simpleutil.py b/modules/base/simpleutil.py
new file mode 100644
index 00000000..53ce58ab
--- /dev/null
+++ b/modules/base/simpleutil.py
@@ -0,0 +1,70 @@
+
+#
+#  Aura Engine
+#
+#  Playout Daemon for autoradio project
+#
+#
+#  Copyright (C) 2020 David Trattnig <david.trattnig@subsquare.at>
+#
+#  This file is part of engine.
+#
+#  engine is free software: you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation, either version 3 of the License, or
+#  any later version.
+#
+#  engine is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with engine. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# Meta
+__version__ = '0.0.1'
+__license__ = "GNU General Public License (GPL) Version 3"
+__version_info__ = (0, 0, 1)
+__author__ = 'David Trattnig <david.trattnig@subsquare.at>'
+
+
+import datetime
+import time
+
+
+
+class SimpleUtil:
+    """
+    A container for simple utility methods.
+    """
+
+
+    @staticmethod
+    def fmt_time(timestamp):
+        """
+        Formats a UNIX timestamp to a String displaying time in the format '%H:%M:%S'.
+
+        Args:
+            (Integer) timestamp:    Unix epoch
+
+        Returns:
+            (String): Displaying the time
+        """
+        return datetime.datetime.fromtimestamp(timestamp).strftime('%H:%M:%S')
+
+
+    @staticmethod
+    def timestamp(date_and_time=datetime.datetime.now()):
+        """
+        Transforms the given `datetime` into a UNIX epoch timestamp.
+        If no parameter is passed, the current timestamp is returned.
+        
+        Args:
+            (Datetime) date_and_time:    the date and time to transform.
+
+        Returns: 
+            (Integer): timestamp in seconds.
+        """
+        return time.mktime(date_and_time.timetuple())
-- 
GitLab