[elbe-devel] [PATCH 1/2] elbepack: parselicence: explicitly use UTC for created field

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Jul 24 10:31:23 CEST 2024


The timestamp without timezone is of limited utility.
Use UTC as standard timezone.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/commands/parselicence.py               | 5 +++--
 elbepack/tests/test_parselicence.py             | 2 +-
 elbepack/tests/test_parselicence_reference.spdx | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/elbepack/commands/parselicence.py b/elbepack/commands/parselicence.py
index 407374d0940d..78659e79fbd2 100644
--- a/elbepack/commands/parselicence.py
+++ b/elbepack/commands/parselicence.py
@@ -3,10 +3,10 @@
 # SPDX-FileCopyrightText: 2016-2017 Linutronix GmbH
 
 import argparse
+import datetime
 import io
 import os
 import subprocess
-from datetime import datetime
 from tempfile import NamedTemporaryFile
 
 from elbepack.treeutils import etree
@@ -227,13 +227,14 @@ def run_command(argv):
             tree.root.remove_child(pkg)
 
     if args.tagvalue is not None:
+        created = datetime.datetime.now(datetime.timezone.utc).isoformat(timespec='seconds')
         with io.open(args.tagvalue, 'wt', encoding='utf-8') as fp:
             fp.write('SPDXVersion: SPDX-1.2\n')
             fp.write('DataLicense: CC0-1.0\n')
             fp.write('\n')
             fp.write('## Creation Information\n')
             fp.write(f'Creator: Tool: elbe-{elbe_version}\n')
-            fp.write(f'Created: {datetime.now().isoformat()}\n')
+            fp.write(f'Created: {created}\n')
             fp.write('\n')
             fp.write('\n')
             fp.write('## Package Information\n')
diff --git a/elbepack/tests/test_parselicence.py b/elbepack/tests/test_parselicence.py
index 6f68c9012f31..342b57043521 100644
--- a/elbepack/tests/test_parselicence.py
+++ b/elbepack/tests/test_parselicence.py
@@ -12,7 +12,7 @@ here = pathlib.Path(__file__).parent
 
 def _replace_changing_spdx_data(s):
     s = re.sub(r'\nCreator: Tool: .*\n', r'\nCreator: Tool: INVALID\n', s)
-    s = re.sub(r'\nCreated: .*\n', r'\nCreated: 0001-01-01T00:00:00.000000\n', s)
+    s = re.sub(r'\nCreated: .*\n', r'\nCreated: 0001-01-01T00:00:00+00:00\n', s)
     return s
 
 
diff --git a/elbepack/tests/test_parselicence_reference.spdx b/elbepack/tests/test_parselicence_reference.spdx
index 08628aac635f..4175957017c3 100644
--- a/elbepack/tests/test_parselicence_reference.spdx
+++ b/elbepack/tests/test_parselicence_reference.spdx
@@ -3,7 +3,7 @@ DataLicense: CC0-1.0
 
 ## Creation Information
 Creator: Tool: INVALID
-Created: 0001-01-01T00:00:00.000000
+Created: 0001-01-01T00:00:00+00:00
 
 
 ## Package Information

-- 
2.45.2



More information about the elbe-devel mailing list