tools: fw-update: allow ISO 8610 date formats
Currently, the ReleaseDateTime data is expected to be in a
"%d/%m/%Y %H:%M:%S" format.
However, this is ambiguous (ie., is locale-specific).
This change adds supoort to allow an ISO 8601 format of:
"%Y-%m-%dT%H:%M:%S"
and a relaxed version with the 'T' separator replaced with a space:
"%Y-%m-%d %H:%M:%S"
Update the readme and example json to switch to the preferred format.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Change-Id: Ica3ae824979df6b666b8abb619ceaedffd90b374
diff --git a/tools/fw-update/pldm_fwup_pkg_creator.py b/tools/fw-update/pldm_fwup_pkg_creator.py
index 0209f1a..b61afa5 100755
--- a/tools/fw-update/pldm_fwup_pkg_creator.py
+++ b/tools/fw-update/pldm_fwup_pkg_creator.py
@@ -186,9 +186,22 @@
)
if release_date_time_str is not None:
- release_date_time = datetime.strptime(
- release_date_time_str, "%d/%m/%Y %H:%M:%S"
- )
+ formats = [
+ "%Y-%m-%dT%H:%M:%S",
+ "%Y-%m-%d %H:%M:%S",
+ "%d/%m/%Y %H:%M:%S",
+ ]
+ release_date_time = None
+ for fmt in formats:
+ try:
+ release_date_time = datetime.strptime(
+ release_date_time_str, fmt
+ )
+ break
+ except ValueError:
+ pass
+ if release_date_time is None:
+ sys.exit("Can't parse release date '%s'" % release_date_time_str)
else:
release_date_time = datetime.now()