+ /*
+ * You need to use 2 locale variables to get the first day of the week.
+ * This is needed to support first_weekday=2 and first_workday=1 for
+ * the rare case where working days span across 2 weeks.
+ * This shell script shows the combinations and calculations involved:
+
+ for LANG in en_US ru_RU fr_FR csb_PL POSIX; do
+ printf "%s:\t%s + %s -1 = " $LANG $(locale week-1stday first_weekday)
+ date -d"$(locale week-1stday) +$(($(locale first_weekday)-1))day" +%w
+ done
+
+ en_US: 19971130 + 1 -1 = 0 #0 = sunday
+ ru_RU: 19971130 + 2 -1 = 1
+ fr_FR: 19971201 + 1 -1 = 1
+ csb_PL: 19971201 + 2 -1 = 2
+ POSIX: 19971201 + 7 -1 = 0
+ */
+ {
+ int wfd;
+ union { unsigned int word; char *string; } val;
+ val.string = nl_langinfo(_NL_TIME_WEEK_1STDAY);
+
+ wfd = val.word;
+ wfd = day_in_week(wfd % 100, (wfd / 100) % 100, wfd / (100 * 100));
+ weekstart = (wfd + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % 7;
+ }