Pan view calendar - use locale to set first day of week
authorColin Clark <colin.clark@cclark.uk>
Sat, 26 May 2018 19:20:01 +0000 (20:20 +0100)
committerColin Clark <colin.clark@cclark.uk>
Sat, 26 May 2018 19:20:01 +0000 (20:20 +0100)
src/misc.c
src/misc.h
src/pan-view/pan-calendar.c

index a06e791..9aa9c4e 100644 (file)
@@ -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 @@ int runcmd(gchar *cmd)
 #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: */
index 1be461e..c9cf35b 100644 (file)
@@ -27,6 +27,6 @@ gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive);
 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: */
index 3400fbb..004a045 100644 (file)
@@ -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 @@ void pan_calendar_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *he
                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;