changeset 2760:8c1423d43ec2

Pan view calendar - use locale to set first day of week
author Colin Clark <colin.clark@cclark.uk>
date Sat, 26 May 2018 20:20:01 +0100
parents dc29a31b7c47
children 031705583caf
files src/misc.c src/misc.h src/pan-view/pan-calendar.c
diffstat 3 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/misc.c	Thu May 24 19:25:45 2018 +0100
+++ b/src/misc.c	Sat May 26 20:20:01 2018 +0100
@@ -22,6 +22,8 @@
 #include "misc.h"
 #include "ui_fileops.h"
 
+#include <langinfo.h>
+
 gdouble get_zoom_increment(void)
 {
 	return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 100.0 : 1.0);
@@ -237,5 +239,18 @@
 #endif
 }
 
+/**
+ * @brief Returns integer representing first_day_of_week
+ * @returns Integer in range 1 to 7
+ * 
+ * Uses current locale to get first day of week
+ * 
+ * Sunday == 1
+ */
+gint date_get_first_day_of_week()
+{
+	return nl_langinfo(_NL_TIME_FIRST_WEEKDAY)[0];
+}
+
 
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/misc.h	Thu May 24 19:25:45 2018 +0100
+++ b/src/misc.h	Sat May 26 20:20:01 2018 +0100
@@ -27,6 +27,6 @@
 gchar *expand_tilde(const gchar *filename);
 int runcmd(gchar *cmd);
 gchar *decode_geo_parameters(const gchar *input_text);
-
+gint date_get_first_day_of_week();
 #endif /* MISC_H */
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/pan-view/pan-calendar.c	Thu May 24 19:25:45 2018 +0100
+++ b/src/pan-view/pan-calendar.c	Sat May 26 20:20:01 2018 +0100
@@ -24,6 +24,7 @@
 #include <glib/gprintf.h>
 #include <math.h>
 
+#include "misc.h"
 #include "pan-util.h"
 #include "pan-view.h"
 #include "pan-view-filter.h"
@@ -293,6 +294,8 @@
 		days = pan_date_value(dt, PAN_DATE_LENGTH_DAY);
 		dt = pan_date_to_time(year, month, 1);
 		col = pan_date_value(dt, PAN_DATE_LENGTH_WEEK);
+		col = col - (date_get_first_day_of_week() - 1);
+		if (col < 0) col = col + 7;
 		row = 1;
 
 		x = PAN_BOX_BORDER;