firmware: Change date format

New sysrepo needs the "-00:00" instead of the "Z".

Change-Id: I33ff38fa0b0b7ad806a8e7309950bbae0222c85c
diff --git a/src/system/Firmware.cpp b/src/system/Firmware.cpp
index b2e249f..02d0f74 100644
--- a/src/system/Firmware.cpp
+++ b/src/system/Firmware.cpp
@@ -5,6 +5,7 @@
  *
  */
 
+#include <regex>
 #include "Firmware.h"
 #include "utils/log.h"
 #include "utils/sysrepo.h"
@@ -16,7 +17,8 @@
 const auto CZECHLIGHT_SYSTEM_MODULE_NAME = "czechlight-system"s;
 const auto CZECHLIGHT_SYSTEM_FIRMWARE_MODULE_PREFIX = "/"s + CZECHLIGHT_SYSTEM_MODULE_NAME + ":firmware/"s;
 const auto FIRMWARE_SLOTS = {"rootfs.0"s, "rootfs.1"s};
-
+// Modified regex of yang:date-and-time
+const auto DATE_TIME_REGEX = std::regex{R"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)"};
 }
 
 namespace velia::system {
@@ -134,7 +136,7 @@
 
     for (const auto& slotName : FIRMWARE_SLOTS) {
         if (auto it = slotStatus.find(slotName); it != slotStatus.end()) { // if there is an update for the slot "slotName"
-            const auto& props = it->second;
+            auto& props = it->second;
             std::string xpathPrefix;
 
             // Better be defensive about provided properties. If somebody removes /slot.raucs, RAUC doesn't provide all the data (at least bundle.version and installed.timestamp).
@@ -145,6 +147,17 @@
                 continue;
             }
 
+            // sysrepo needs the "-00:00" suffix instead of the "Z" suffix.
+            if (auto pit = props.find("installed.timestamp"); pit != props.end()) {
+                auto& ts = std::get<std::string>(pit->second);
+                if (std::regex_match(ts, DATE_TIME_REGEX)) {
+                    ts.pop_back(); // Get rid of the "Z".
+                    ts.append("-00:00");
+                } else {
+                    m_log->warn("RAUC provided a timestamp in an unexpected format: {}", ts);
+                }
+            }
+
             for (const auto& [yangKey, raucKey] : {std::pair{"state", "state"}, {"boot-status", "boot-status"}, {"version", "bundle.version"}, {"installed", "installed.timestamp"}}) {
                 if (auto pit = props.find(raucKey); pit != props.end()) {
                     m_slotStatusCache[xpathPrefix + yangKey] = std::get<std::string>(pit->second);
diff --git a/tests/sysrepo_system-firmware.cpp b/tests/sysrepo_system-firmware.cpp
index 897e12e..d7b9f26 100644
--- a/tests/sysrepo_system-firmware.cpp
+++ b/tests/sysrepo_system-firmware.cpp
@@ -146,13 +146,13 @@
     REQUIRE(dataFromSysrepo(client, "/czechlight-system:firmware", SR_DS_OPERATIONAL) == std::map<std::string, std::string> {
                 {"/firmware-slot[name='A']", ""},
                 {"/firmware-slot[name='A']/boot-status", "bad"},
-                {"/firmware-slot[name='A']/installed", "2021-01-13T17:15:50Z"},
+                {"/firmware-slot[name='A']/installed", "2021-01-13T17:15:50-00:00"},
                 {"/firmware-slot[name='A']/name", "A"},
                 {"/firmware-slot[name='A']/state", "inactive"},
                 {"/firmware-slot[name='A']/version", "v4-104-ge80fcd4"},
                 {"/firmware-slot[name='B']", ""},
                 {"/firmware-slot[name='B']/boot-status", "good"},
-                {"/firmware-slot[name='B']/installed", "2021-01-13T17:20:15Z"},
+                {"/firmware-slot[name='B']/installed", "2021-01-13T17:20:15-00:00"},
                 {"/firmware-slot[name='B']/name", "B"},
                 {"/firmware-slot[name='B']/state", "booted"},
                 {"/firmware-slot[name='B']/version", "v4-103-g34d2f48"},
@@ -260,13 +260,13 @@
                 REQUIRE(dataFromSysrepo(client, "/czechlight-system:firmware", SR_DS_OPERATIONAL) == std::map<std::string, std::string> {
                     {"/firmware-slot[name='A']", ""},
                     {"/firmware-slot[name='A']/boot-status", "bad"},
-                    {"/firmware-slot[name='A']/installed", "2021-01-13T17:15:50Z"},
+                    {"/firmware-slot[name='A']/installed", "2021-01-13T17:15:50-00:00"},
                     {"/firmware-slot[name='A']/name", "A"},
                     {"/firmware-slot[name='A']/state", "inactive"},
                     {"/firmware-slot[name='A']/version", "v4-104-ge80fcd4"},
                     {"/firmware-slot[name='B']", ""},
                     {"/firmware-slot[name='B']/boot-status", "good"},
-                    {"/firmware-slot[name='B']/installed", "2021-01-13T17:20:15Z"},
+                    {"/firmware-slot[name='B']/installed", "2021-01-13T17:20:15-00:00"},
                     {"/firmware-slot[name='B']/name", "B"},
                     {"/firmware-slot[name='B']/state", "booted"},
                     {"/firmware-slot[name='B']/version", "v4-103-g34d2f48"},
@@ -368,12 +368,12 @@
 
         expected = {
             {"[name='A']/boot-status", "bad"},
-            {"[name='A']/installed", "2021-01-13T17:15:50Z"},
+            {"[name='A']/installed", "2021-01-13T17:15:50-00:00"},
             {"[name='A']/name", "A"},
             {"[name='A']/state", "inactive"},
             {"[name='A']/version", "v4-104-ge80fcd4"},
             {"[name='B']/boot-status", "good"},
-            {"[name='B']/installed", "2021-01-13T17:20:15Z"},
+            {"[name='B']/installed", "2021-01-13T17:20:15-00:00"},
             {"[name='B']/name", "B"},
             {"[name='B']/state", "booted"},
             {"[name='B']/version", "v4-103-g34d2f48"},
@@ -419,7 +419,7 @@
             {"[name='A']/name", "A"},
             {"[name='A']/state", "inactive"},
             {"[name='B']/boot-status", "good"},
-            {"[name='B']/installed", "2021-01-13T17:20:15Z"},
+            {"[name='B']/installed", "2021-01-13T17:20:15-00:00"},
             {"[name='B']/name", "B"},
             {"[name='B']/state", "booted"},
             {"[name='B']/version", "v4-103-g34d2f48"},
@@ -461,7 +461,7 @@
 
         expected = {
             {"[name='B']/boot-status", "good"},
-            {"[name='B']/installed", "2021-01-13T17:20:15Z"},
+            {"[name='B']/installed", "2021-01-13T17:20:15-00:00"},
             {"[name='B']/name", "B"},
             {"[name='B']/state", "booted"},
             {"[name='B']/version", "v4-103-g34d2f48"},