X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_graph.c;h=390a66ec162ebe8ee80c48cf3932a62bf5eab7ed;hp=a93fbb1c52708ca3d047630eb587434c6ac29a00;hb=f467b805f7cbe821d1bfec27ad643067dd19ca10;hpb=f54455954eb3111c1b702d3ed7b9daff833690f3 diff --git a/src/rrd_graph.c b/src/rrd_graph.c index a93fbb1..390a66e 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -29,6 +29,10 @@ #include +#ifdef HAVE_LANGINFO_H +#include +#endif + #include "rrd_graph.h" #include "rrd_client.h" @@ -1356,6 +1360,21 @@ int data_proc( } +static int find_first_weekday(void){ + static int first_weekday = -1; + if (first_weekday == -1){ +#if defined(HAVE_NL_LANGINFO) + /* according to http://sourceware.org/ml/libc-locales/2009-q1/msg00011.html */ + long week_1stday_l = (long) nl_langinfo (_NL_TIME_WEEK_1STDAY); + if (week_1stday_l == 19971130) first_weekday = 0; /* Sun */ + else if (week_1stday_l == 19971201) first_weekday = 1; /* Mon */ + else first_weekday = 1; /* we go for a monday default */ +#else + first_weekday = 1; +#endif + } + return first_weekday; +} /* identify the point where the first gridline, label ... gets placed */ @@ -1397,10 +1416,10 @@ time_t find_first_time( tm. tm_sec = 0; tm. tm_min = 0; tm. tm_hour = 0; - tm. tm_mday -= tm.tm_wday - 1; /* -1 because we want the monday */ + tm. tm_mday -= tm.tm_wday - find_first_weekday(); - if (tm.tm_wday == 0) - tm. tm_mday -= 7; /* we want the *previous* monday */ + if (tm.tm_wday == 0 && find_first_weekday() > 0) + tm. tm_mday -= 7; /* we want the *previous* week */ break; case TMT_MONTH: