Bug 181 - [PATCH] POSIX first_weekday should be sunday
Summary: [PATCH] POSIX first_weekday should be sunday
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: localedata (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Petter Reinholdtsen
URL:
Keywords: testsuite
Depends on:
Blocks:
 
Reported: 2004-05-25 21:48 UTC by Petter Reinholdtsen
Modified: 2012-03-08 04:38 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Patch to fix first_weekday for POSIX / C locale (284 bytes, patch)
2004-05-25 21:51 UTC, Petter Reinholdtsen
Details | Diff
Fix first_weekday and first_workday for POSIX file and inline POSIX. (366 bytes, patch)
2006-02-21 21:53 UTC, Dwayne Grant McConnell
Details | Diff
Testcase for POSIX/C first_weekday and first_workday. (368 bytes, text/plain)
2006-02-21 21:54 UTC, Dwayne Grant McConnell
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Petter Reinholdtsen 2004-05-25 21:48:48 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.
Comment 1 Petter Reinholdtsen 2004-05-25 21:51:08 UTC
Created attachment 93 [details]
Patch to fix first_weekday for POSIX / C locale
Comment 2 Petter Reinholdtsen 2004-05-26 11:45:28 UTC
I've sent the patch to libc-alpha@ today.
Comment 3 Egmont Koblinger 2005-10-06 18:35:37 UTC
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.
Comment 4 Egmont Koblinger 2005-10-07 14:00:04 UTC
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.
Comment 5 Dwayne Grant McConnell 2006-02-21 21:53:47 UTC
Created attachment 882 [details]
Fix first_weekday and first_workday for POSIX file and inline POSIX.
Comment 6 Dwayne Grant McConnell 2006-02-21 21:54:17 UTC
Created attachment 883 [details]
Testcase for POSIX/C first_weekday and first_workday.
Comment 7 Dwayne Grant McConnell 2006-02-21 21:57:37 UTC
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.)
Comment 8 Stanislav Brabec 2006-02-28 21:16:28 UTC
Related: bug 2388.
Comment 9 Ulrich Drepper 2007-10-07 20:41:05 UTC
I've checked appropriate patchesin cvs.