Add helper to format epoch time with windows
authorAndre Heinecke <aheinecke@intevation.de>
Mon, 17 Oct 2016 16:41:08 +0000 (18:41 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Mon, 17 Oct 2016 16:41:08 +0000 (18:41 +0200)
* src/common.c (epoch_to_file_time): New.
(format_date_from_gpgme): New.

--
Format's an unsinged long into a string according to the users
locale.

src/common.c
src/common.h

index 557bc2a..42598f9 100644 (file)
@@ -819,3 +819,37 @@ get_gpg4win_dir()
     }
   return NULL;
 }
+
+
+static void
+epoch_to_file_time (unsigned long time, LPFILETIME pft)
+{
+ LONGLONG ll;
+
+ ll = Int32x32To64(time, 10000000) + 116444736000000000;
+ pft->dwLowDateTime = (DWORD)ll;
+ pft->dwHighDateTime = ll >> 32;
+}
+
+char *
+format_date_from_gpgme (unsigned long time)
+{
+  wchar_t buf[256];
+  FILETIME ft;
+  SYSTEMTIME st;
+
+  epoch_to_file_time (time, &ft);
+  FileTimeToSystemTime(&ft, &st);
+  int ret = GetDateFormatEx (NULL,
+                             DATE_SHORTDATE,
+                             &st,
+                             NULL,
+                             buf,
+                             256,
+                             NULL);
+  if (ret == 0)
+    {
+      return NULL;
+    }
+  return wchar_to_utf8 (buf);
+}
index 9a3887c..70b4ee7 100644 (file)
@@ -116,6 +116,8 @@ char *percent_escape (const char *str, const char *extra);
 
 void fix_linebreaks (char *str, int *len);
 
+char *format_date_from_gpgme (unsigned long time);
+
 /*-- main.c --*/
 const void *get_128bit_session_key (void);
 const void *get_64bit_session_marker (void);