]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Implement first_weekday under Windows
authorWolfgang Stöggl <c72578@yahoo.de>
Mon, 17 Jun 2019 19:47:29 +0000 (21:47 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Tue, 18 Jun 2019 06:17:46 +0000 (08:17 +0200)
- Use GetLocaleInfoEx() to obtain the first weekday

src/rrd_graph.c
src/rrd_rpncalc.c

index 62c3e645f0cce0bee8fc2c0d642587e07afae3b9..c53dcc2e09067cc4b64be750ab5517b2c9298844 100644 (file)
@@ -45,6 +45,7 @@
 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
 #include <io.h>
 #include <fcntl.h>
+#include <windows.h>    /* for GetLocaleInfoEx */
 #endif
 
 #include <time.h>
@@ -1564,13 +1565,25 @@ static int find_first_weekday(
             week_1stday = 1;    /* Mon */
         else {
             first_weekday = 1;
-            return first_weekday;   /* we go for a monday default */
+            return first_weekday;   /* we go for a Monday default */
         }
         first_weekday = (week_1stday + first_weekday - 1) % 7;
+#elif defined(_WIN32) && defined(LOCALE_NAME_USER_DEFAULT)
+        const char wsDay[4];    /* sscanf requires const char */
+
+        GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK,
+                        (LPWSTR) & wsDay, 4);
+        sscanf(wsDay, "%d", &first_weekday);
+        /* 0:Monday, ..., 6:Sunday. */
+        /* We need 1 for Monday, 0 for Sunday. */
+        first_weekday = (first_weekday + 1) % 7;
 #else
         first_weekday = 0;
 #endif
     }
+#ifdef DEBUG
+    printf("first_weekday = %d\n", first_weekday);
+#endif
     return first_weekday;
 }
 
index 9308cb35709023d3aecd0dc185b10628c134e424..c18eaa5c230e3d54813e28ccbf390313ea4e4f7d 100644 (file)
 #ifdef HAVE_LANGINFO_H
 #include <langinfo.h>
 #endif
+#ifdef _WIN32
+#include <windows.h>    /* for GetLocaleInfoEx */
+#endif
 #include "rrd_strtod.h"
 #include "rrd_tool.h"
 #include "rrd_rpncalc.h"
 // #include "rrd_graph.h"
 
+/* #define DEBUG */
+
 static short addop2str(
     enum op_en op,
     enum op_en op_type,
@@ -567,13 +572,25 @@ static int find_first_weekday(
             week_1stday = 1;    /* Mon */
         else {
             first_weekday = 1;
-            return first_weekday;   /* we go for a monday default */
+            return first_weekday;   /* we go for a Monday default */
         }
         first_weekday = (week_1stday + first_weekday - 1) % 7;
+#elif defined(_WIN32) && defined(LOCALE_NAME_USER_DEFAULT)
+        const char wsDay[4];    /* sscanf requires const char */
+
+        GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK,
+                        (LPWSTR) & wsDay, 4);
+        sscanf(wsDay, "%d", &first_weekday);
+        /* 0:Monday, ..., 6:Sunday. */
+        /* We need 1 for Monday, 0 for Sunday. */
+        first_weekday = (first_weekday + 1) % 7;
 #else
         first_weekday = 0;
 #endif
     }
+#ifdef DEBUG
+    printf("first_weekday = %d\n", first_weekday);
+#endif
     return first_weekday;
 }