From 17cfb1569bc2ff5311aa0ee7ed643a3e09bf808b Mon Sep 17 00:00:00 2001
From: Christoph Alt <christoph.alt@fau.de>
Date: Fri, 24 Feb 2023 08:35:47 +0100
Subject: [PATCH] moved function to extract the timestamp from env here

---
 cbutil/util.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/cbutil/util.py b/cbutil/util.py
index 8b8312b..9625540 100644
--- a/cbutil/util.py
+++ b/cbutil/util.py
@@ -1,6 +1,8 @@
 import logging
 import operator
 import os
+import time
+
 from datetime import datetime
 from functools import reduce
 from pathlib import Path
@@ -71,5 +73,17 @@ def time_conversion(time_stamp, *, pattern="%Y-%m-%d %H:%M:%S"):
     return int(dt.timestamp())
 
 
+def get_time_stamp_from_env(key='CI_PIPELINE_CREATED_AT'):
+    """
+        Try to get the time stamp from the environment and
+        convert it to an int. If that fails use the current time
+    """
+    try:
+        return time_conversion(os.environ[key])
+    except KeyError:
+        logger.debug(f'Could not find timestamp with ${key}')
+        return int(time.time())
+
+
 def get_from_nested_dict(nested_dict, keys):
     return reduce(operator.getitem, keys, nested_dict)
-- 
GitLab