From d83ffcb3e624beb2a7533b8f059b1f239a7fe429 Mon Sep 17 00:00:00 2001 From: oetiker Date: Sun, 7 Feb 2010 19:48:01 +0000 Subject: [PATCH] use locale information from LC_TIME first_weekday to determine if the week should start sunday or monday. git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@2017 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/configure.ac | 4 ++-- program/src/rrd_graph.c | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/program/configure.ac b/program/configure.ac index 235625c9..07231b79 100644 --- a/program/configure.ac +++ b/program/configure.ac @@ -182,7 +182,7 @@ CONFIGURE_PART(Checking for Header Files) dnl Checks for header files. AC_HEADER_STDC AC_HEADER_DIRENT -AC_CHECK_HEADERS(stdint.h inttypes.h libgen.h features.h sys/stat.h sys/types.h fcntl.h fp_class.h malloc.h unistd.h ieeefp.h math.h sys/times.h sys/param.h sys/resource.h signal.h float.h stdio.h stdlib.h errno.h string.h ctype.h) +AC_CHECK_HEADERS(langinfo.h stdint.h inttypes.h libgen.h features.h sys/stat.h sys/types.h fcntl.h fp_class.h malloc.h unistd.h ieeefp.h math.h sys/times.h sys/param.h sys/resource.h signal.h float.h stdio.h stdlib.h errno.h string.h ctype.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -209,7 +209,7 @@ AC_C_BIGENDIAN dnl for each function found we get a definition in config.h dnl of the form HAVE_FUNCTION -AC_CHECK_FUNCS(tzset fsync mbstowcs opendir readdir chdir chroot getuid strerror snprintf vsnprintf vasprintf fpclass class fp_class isnan memmove strchr mktime getrusage gettimeofday) +AC_CHECK_FUNCS(nl_langinfo tzset fsync mbstowcs opendir readdir chdir chroot getuid strerror snprintf vsnprintf vasprintf fpclass class fp_class isnan memmove strchr mktime getrusage gettimeofday) AC_FUNC_STRERROR_R diff --git a/program/src/rrd_graph.c b/program/src/rrd_graph.c index a93fbb1c..bd7e3c34 100644 --- a/program/src/rrd_graph.c +++ b/program/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,17 @@ int data_proc( } +static int find_first_weekday(void){ + static int first_weekday = -1; + if (first_weekday == -1){ +#if defined(HAVE_NL_LANGINFO) + first_weekday = nl_langinfo(_NL_TIME_FIRST_WEEKDAY)[0] - 1; +#else + first_weekday = 1; +#endif + } + return first_weekday; +} /* identify the point where the first gridline, label ... gets placed */ @@ -1397,10 +1412,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: -- 2.30.2