Sources Bugzilla – Bug 181
[PATCH] POSIX first_weekday should be sunday
Last modified: 2012-03-08 04:38:13 UTC
At the moment, the first_weekday value for POSIX and C locale is saturday. It should be sunday. This test program demonstrates the problem: #include <stdio.h> #include <locale.h> #include <langinfo.h> int main() { char *locale = "C"; int week_1stday; int first_weekday; int first_workday; setlocale(LC_TIME, locale); week_1stday = (int)nl_langinfo(_NL_TIME_WEEK_1STDAY); first_weekday = *nl_langinfo(_NL_TIME_FIRST_WEEKDAY); first_workday = *nl_langinfo(_NL_TIME_FIRST_WORKDAY); printf("week_1stday for '%s' locale = %d\n", locale, week_1stday); printf("first_weekday for '%s' locale = %d\n", locale, first_weekday); printf("first_workday for '%s' locale = %d\n", locale, first_workday); return 0; } It should print '1' for first_weekday, but prints 7 instead. The first_* values are relative to the week_1stday date. The value 19971130 is a sunday, so 1 would be a sunday while 7 would be a saturday. I'll attach a patch which I believe fixes the issue.
Created attachment 93 [details] Patch to fix first_weekday for POSIX / C locale
I've sent the patch to libc-alpha@ today.
Today I spent some time trying to understand the locale fields "week" and "first_weekday" to fix the Hungarian locale (bug #1429). It all started with a Gnome update, Gnome 2.8 presented a Monday-based calendar, while 2.12 brought me to a Sunday-based one which is unusable most Hungarian people (well, at least for me :-) so I wanted to fix it. Then it turned out that new Gnome uses these fields from glibc... After all, I came to exactly the same conclusion as Petter. "first_weekday" is relative to the date (usually 19971130 or 19971201) defined in the "week" field (which is later available as "week-1stday". As a result, currently glibc's C locale defines that a calendar should be displayed as if weeks started on Saturday. In accordance, if I start Gnome with LC_ALL=POSIX, its calendar really displays weeks from Saturday to Friday.
One more note: The localedata tree has a file named POSIX, and based on it the locale-archive database also has a POSIX entry. This file contains no "week" or "first_weekday" entries, so the glibc built-in default, 19971130 and 1 are used, which would lead to a calendar displayed beginning with Sunday if this locale entry would be reachable, but it isn't, since the built-in POSIX locale is used whenever the POSIX locale is requested. So glibc is inconsistent with itself, its built-in POSIX is different from what the file called POSIX says. This means that if someone creates a locale which copies the POSIX locale's time stuff: LC_TIME copy "POSIX" END LC_TIME then this locale will behave differently than the POSIX locale, as this new external locale will start the weeks on Sunday, unlike built-in POSIX.
Created attachment 882 [details] Fix first_weekday and first_workday for POSIX file and inline POSIX.
Created attachment 883 [details] Testcase for POSIX/C first_weekday and first_workday.
I attached a patch and testcase to fix first_weekday and first_workday and test those two plus week_1stday. But I cannot find the standards text which specifies first_weekday and first_workday so I'm not 100% this is the right thing to do. I found one comment on a gentoo page stating that these are not part of the standard FWIW. http://gentoo-wiki.com/HOWTO_localedef (Also this bug is only for first_weekday so changing first_workday may not be needed but it seemed logical to me and I saw similar settings in other locale files.)
Related: bug 2388.
I've checked appropriate patchesin cvs.