From a98981d6cc2741f9af00302321d810bff7215d51 Mon Sep 17 00:00:00 2001
From: Constantin P <papizh.konstantin@demlabs.net>
Date: Wed, 10 Jan 2024 17:06:19 +0700
Subject: [PATCH] Timestamp output fixed

---
 core/src/dap_time.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/core/src/dap_time.c b/core/src/dap_time.c
index 68c95891f..757b8b780 100644
--- a/core/src/dap_time.c
+++ b/core/src/dap_time.c
@@ -137,27 +137,25 @@ int dap_time_to_str_rfc822(char *a_out, size_t a_out_size_max, dap_time_t a_time
     time_t l_time = a_time;
     l_tmp = localtime(&l_time);
     if (!l_tmp) {
-        log_it(L_ERROR, "Can't convert data from unix fromat to structured one");
+        log_it(L_ERROR, "Can't convert data from unix format to structured one");
         return -2;
     }
-    int l_ret = strftime(a_out, a_out_size_max, "%a, %d %b %y %H:%M:%S %z", l_tmp);
+    int l_ret = strftime(a_out, a_out_size_max, "%a, %d %b %y %H:%M:%S"
+                     #ifndef DAP_OS_WINDOWS
+                                                " %z"
+                     #endif
+                         , l_tmp);
     if (!l_ret) {
-        log_it( L_ERROR, "Can't print formatted time in string");
+        log_it(L_ERROR, "Can't print formatted time in string");
         return -1;
     }
 #ifdef DAP_OS_WINDOWS
     // %z is unsupported on Windows platform
     TIME_ZONE_INFORMATION l_tz_info;
     GetTimeZoneInformation(&l_tz_info);
-    char l_shift = strlen(l_ret);
-    int l_tz_diff = -(l_tz_info.Bias / 60);
-    int l_count = snprintf(l_ret + l_shift, a_out_size_max - l_shift, "%02d", l_tz_diff);
-    if (l_count > 0 && l_shift + l_count < a_out_size_max)
-        l_shift += l_count;
-    else
-        return l_ret;
-    int l_tz_minutes = l_tz_info.Bias % 60;
-    snprintf(l_ret + l_shift, a_out_size_max - l_shift, "%02d", l_tz_minutes);
+    char l_tz_str[8] = { '\0' };
+    snprintf(l_tz_str, sizeof(l_tz_str), " +%02d%02d", -(l_tz_info.Bias / 60), l_tz_info.Bias % 60);
+    l_ret += snprintf(a_out + l_ret, a_out_size_max - l_ret, l_tz_str);
 #endif
     return l_ret;
 }
-- 
GitLab