From: Wolfgang Stöggl Date: Mon, 17 Jun 2019 19:47:29 +0000 (+0200) Subject: Implement first_weekday under Windows X-Git-Tag: v1.8.0~89 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=e3a1c280f50c5288d3b000aa17c6a7788430cf33;p=thirdparty%2Frrdtool-1.x.git Implement first_weekday under Windows - Use GetLocaleInfoEx() to obtain the first weekday --- diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 62c3e645..c53dcc2e 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -45,6 +45,7 @@ #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include #include +#include /* for GetLocaleInfoEx */ #endif #include @@ -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; } diff --git a/src/rrd_rpncalc.c b/src/rrd_rpncalc.c index 9308cb35..c18eaa5c 100644 --- a/src/rrd_rpncalc.c +++ b/src/rrd_rpncalc.c @@ -13,11 +13,16 @@ #ifdef HAVE_LANGINFO_H #include #endif +#ifdef _WIN32 +#include /* 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; }