From 78b1ed5436ee44fc35ed9ea10baaefbbca4755ec Mon Sep 17 00:00:00 2001
From: Karim Ahmed <karim.ahmed@xfel.eu>
Date: Mon, 1 Mar 2021 13:05:43 +0100
Subject: [PATCH] get time zone info

---
 cal_tools/cal_tools/tools.py | 3 ++-
 tests/test_cal_tools.py      | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py
index f112c3cf0..1b5707a37 100644
--- a/cal_tools/cal_tools/tools.py
+++ b/cal_tools/cal_tools/tools.py
@@ -275,7 +275,8 @@ def get_dir_creation_date(directory: Union[str, Path], run: int,
             rfile = sorted(rfiles, key=path.getmtime)[0]
             with h5py.File(rfile, 'r') as fin:
                 cdate = fin['METADATA/creationDate'][0].decode()
-                cdate = datetime.datetime.strptime(cdate, "%Y%m%dT%H%M%SZ")
+                cdate = datetime.datetime.strptime(cdate,
+                    "%Y%m%dT%H%M%SZ").replace(tzinfo=datetime.timezone.utc)
             return cdate
         except (IndexError, IOError, ValueError):
             ntries -= 1
diff --git a/tests/test_cal_tools.py b/tests/test_cal_tools.py
index 24d61719c..7fe26e12a 100644
--- a/tests/test_cal_tools.py
+++ b/tests/test_cal_tools.py
@@ -20,7 +20,7 @@ def test_dir_creation_date():
 
     date = get_dir_creation_date(folder, 9983)
     assert isinstance(date, datetime)
-    assert str(date) == '2020-09-23 13:30:50'
+    assert str(date) == '2020-09-23 13:30:50+00:00'
 
     with pytest.raises(ValueError) as e:
         get_dir_creation_date(folder, 4)
-- 
GitLab