After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 314473 - gtk calendar not calculating first week day correctly
gtk calendar not calculating first week day correctly
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
2.8.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 317723 317946 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2005-08-25 17:05 UTC by JP Rosevear
Modified: 2011-02-04 16:19 UTC
See Also:
GNOME target: ---
GNOME version: 2.11/2.12


Attachments
gtk+-first_weekday.patch (1.00 KB, patch)
2005-09-07 16:54 UTC, Stanislav Brabec
none Details | Review
gtk+-first_weekday-new.patch (1.53 KB, patch)
2006-02-22 15:46 UTC, Michal Marek
none Details | Review

Description JP Rosevear 2005-08-25 17:05:56 UTC
Please describe the problem:
gtkcalendar.c contains:

#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
  week_start = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
  priv->week_start = *((unsigned char *) week_start) % 7 - 1;
#else

week_start is 7 priv->week_start calculates to -1.

Also note, that against glibc 2.3.5, the days appear to go from 1 (monday) to 7
(sunday).

Steps to reproduce:


Actual results:


Expected results:


Does this happen every time?


Other information:
Comment 1 JP Rosevear 2005-08-25 17:11:48 UTC
The test program:

#include <langinfo.h>
#include <stdio.h>

int
main (int argc, char **argv)
{
        char *week_start;

        week_start = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
        printf ("Week start day %d\n", *week_start);
        printf ("Gtk calculated week start day %d\n", *((unsigned char *)
week_start) % 7 - 1);
}
Comment 2 JP Rosevear 2005-08-25 17:12:38 UTC
jpr@bishop:~> ./langinfo
Week start day 7
Gtk calculated week start day -1

jpr@bishop:~> locale -k -c LC_TIME
LC_TIME
abday="Sun;Mon;Tue;Wed;Thu;Fri;Sat"
day="Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday"
abmon="Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec"
mon="January;February;March;April;May;June;July;August;September;October;November;December"
am_pm="AM;PM"
d_t_fmt="%a %d %b %Y %r %Z"
d_fmt="%m/%d/%Y"
t_fmt="%r"
t_fmt_ampm="%I:%M:%S %p"
era=
era_year=""
era_d_fmt=""
alt_digits=
era_d_t_fmt=""
era_t_fmt=""
time-era-num-entries=0
time-era-entries="S"
week-ndays=7
week-1stday=19971201
week-1stweek=4
first_weekday=1
first_workday=1
cal_direction=1
timezone=""
date_fmt="%a %b %e %H:%M:%S %Z %Y"
time-codeset="UTF-8"
Comment 3 JP Rosevear 2005-08-25 17:18:23 UTC
So instead of :
*((unsigned char *) week_start) % 7 - 1

If the week days are 1 (sunday) to 7 (saturday):
(*((unsigned char *) week_start) - 1 ) % 7 

And if they are 1 (monday) to 7 (sunday):
*((unsigned char *) week_start) % 7 

Or something like that - not sure why we are %7 in the first case, would the
return value really overflow 1-7?
Comment 4 Matthias Clasen 2005-08-26 06:28:49 UTC
2005-08-26  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkcalendar.c (gtk_calendar_init): Fix the calculation
	of week_start.  (#314473, JP Rosevaar)
Comment 5 Stanislav Brabec 2005-09-07 16:54:35 UTC
Created attachment 51928 [details] [review]
gtk+-first_weekday.patch

Fix in gtk+-2.8.3 does not work properly with latest SuSE 10.0 beta glibc.

This patch works for me with latest SuSE glibc and C en_US.UTF-8 and
cs_CZ.UTF-8 locales.

I guess that it maybe will not work properly in older glibc versions.
Comment 6 Stanislav Brabec 2005-09-07 16:55:30 UTC
Related: https://bugzilla.novell.com/show_bug.cgi?id=104417
Comment 7 Matthias Clasen 2005-09-08 00:59:38 UTC
Please reopen bugs when adding information
Comment 8 Matthias Clasen 2005-09-08 05:33:39 UTC
Hmm, patch looks right according to my study of iso 14652. I guess we can
assume that _NL_TIME_WEEK_1STDAY is defined when _NL_TIME_FIRST_WEEKDAY is.
Comment 9 Stanislav Brabec 2005-09-08 09:17:42 UTC
Patch needs to be tested with older glibc versions.

You can make added code optional with HAVE__NL_TIME_WEEK_1STDAY. Default value
of week_startsub defined above is 1, i. e. original value, which was working
with old glibc.

I do not have permission to reopen bugs not reported by me or assigned to me.
Comment 10 Matthias Clasen 2005-09-08 12:58:20 UTC
When I asked Uli Drepper, he said that the frirst_weekday handling in glibc has 
not changed in a long time, so if it works on current glibc, it should work on 
suse 9.3 as well.
Comment 11 Stanislav Brabec 2005-09-08 13:04:03 UTC
Yes, I tested "locale -k -c LC_TIME" in 9.3 and it returns the same output as in
10.0.

But old code in gtk+-2.6.x was working OK in SuSE Linux 9.3, but new gtk+-2.8.3
code in 10.0 does not. I don't know, where the change was done.
Comment 12 Matthias Clasen 2005-09-08 13:36:43 UTC
Could be that the localedata changed...
Comment 13 Matthias Clasen 2005-09-09 17:30:36 UTC
2005-09-09  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkcalendar.c (gtk_calendar_init): first_weekday is relative
	to week_1stday, not to Sunday. Gotta love the ISO 14652 guys...
	(#314473, Stanislav Brabec)
Comment 14 Sebastien Bacher 2005-09-29 21:39:14 UTC
I'm not sure if GTK is to blame but since GTK 2.8.4 some locales are not correct.

An example:
http://bugzilla.ubuntu.com/show_bug.cgi?id=16658 for the sv:

week-1stday=19971130
first_weekday=2

But the first week day should be monday ... is there a place explaining exactly
the difference between week-1stday and first_weekday? Why is there 2 different
first days?
Comment 15 Stanislav Brabec 2005-09-30 09:06:48 UTC
It is probably described in ISO 14652 (I don't have access to it).

More can be found in:

http://lists.debian.org/debian-i18n/2005/07/msg00039.html

It would be good to know, whether there are any locale data, which cause bad
result with this patch.
Comment 16 Sebastien Bacher 2005-09-30 09:41:51 UTC
the example from comment #14 is with GTK 2.8.4

"de" locale also has the issue:

week-1stday=19971201
first_weekday=1

So GTK says it starts on sunday where it should start on monday
Comment 17 Stanislav Brabec 2005-09-30 10:37:18 UTC
There must be a bug somewhere or another magic.

For example
LANG=de_DE.UTF-8 locale -k -c LC_TIME | grep '\(day\)'
LANG=en_US.UTF-8 locale -k -c LC_TIME | grep '\(day\)'
returns exactly the same (with exception of translated names). How one can
guess, that de_DE should start by Monday and en_US by Sunday?

CS: Should be Monday
week-1stday=19971130 (week_startsub = 0)
first_weekday=1

DE: Should be Monday
week-1stday=19971201 (week_startsub = 1)
first_weekday=1

US: Should be Sunday
week-1stday=19971201 (week_startsub = 1)
first_weekday=1

C: Should be Sunday?
week-1stday=19971130 (week_startsub = 0)
first_weekday=7
Comment 18 Matthias Clasen 2005-09-30 17:27:30 UTC
so after another close reading of tr 14562, the correct formula is

  (*((unsigned char *) week_start) - 1 + week_startsub) % 7;

but that is not entirely satisfactory for the current locale data either;
it gives:

CS: Sunday
DE: Monday
US: Monday
SV: Monday
C: Saturday

Comment 19 Sebastien Bacher 2005-10-02 10:39:57 UTC
*** Bug 317723 has been marked as a duplicate of this bug. ***
Comment 20 Matthias Clasen 2005-10-03 16:00:09 UTC
Assuming this is fixed now, except for bugs in locale data.
Comment 21 Pierre Ossman 2005-10-03 20:08:30 UTC
I'm not sure this is completely correct now. For sv_SE monday is correctly
displayed as the first day, but it believes today (2005-10-03) is a Tuesday when
it in fact is Monday.

The same thing happens with en_US, which also has Monday as the first day. But I
figure this is also incorrect since Sunday is the first day over there?

en_GB has Sunday as the first day and also calculates the correct weekday for a
date.

C goes really funky and starts the week with Saturday and thinks it's Sunday today.

(Cannot reopen because I'm not owner.)
Comment 22 Matthias Clasen 2005-10-03 20:18:26 UTC
I'll stop hacking and become a farmer :-(
Comment 23 Matthias Clasen 2005-10-03 20:21:00 UTC
reopening
Comment 24 Pierre Ossman 2005-10-03 20:35:25 UTC
Found the problem (besides from the locale bugs).

The computation of the first week day is done _after_ it is used in various
places in the calender widget. So some reorganisation of gtk_calendar_init() is
desperatly needed.
Comment 25 Matthias Clasen 2005-10-03 20:38:10 UTC
At least it has nothing to do with the nl_langinfo() computations...
Comment 26 Matthias Clasen 2005-10-04 03:28:47 UTC
2005-10-03  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkcalendar.c (gtk_calendar_init): Call 
	calendar_compute_days() after setting priv->week_start.
Comment 27 Pierre Ossman 2005-10-04 06:48:54 UTC
Good boy. You can drop the plow for now. ;)

(I.e. patch works fine.)
Comment 28 Sebastien Bacher 2005-10-04 20:35:58 UTC
*** Bug 317946 has been marked as a duplicate of this bug. ***
Comment 29 Michal Marek 2006-02-22 15:46:34 UTC
Created attachment 59937 [details] [review]
gtk+-first_weekday-new.patch

Patch that handles weeks starting by other days than Sunday or Monday
Comment 30 Matthias Clasen 2006-02-22 15:50:45 UTC
Which locale uses a week origin different from 19971130
and 19971201 ?
Comment 31 Michal Marek 2006-02-22 15:53:31 UTC
Can't reopen neither :-(

gtk+-first_weekday.patch handles only Monday and Sunday, but there are locales
starting with Saturday (grep 'calendar:week_start:6' po/*.po).

This patch also handles week-1stday values which aren't in range
19971130..19971206, I don't know if it's really necessary, drop that part if
you don't like it. What's the "right way" to call strptime() in Gtk+ btw? There
is g_date_strftime(), but no counterpart.
Comment 32 Michal Marek 2006-02-22 16:01:19 UTC
(In reply to comment #30)
> Which locale uses a week origin different from 19971130
> and 19971201 ?

None atm :-) But I have put together a patch to glibc's locales based on the
translations of calendar:week_start:0, which also contains locales starting
with Saturday (19971206). See
https://bugzilla.novell.com/show_bug.cgi?id=104417#c20 
Maybe something like that will appear in glibc.
Comment 33 Stanislav Brabec 2006-03-13 10:38:03 UTC
Related glibc localedata bug:
http://sources.redhat.com/bugzilla/show_bug.cgi?id=2388

To Matthias Clasen (comment #30): Many locales use first_weekday=2 (may be a bug), locales for Syrian Arab Republic and Iran use 19971206.

Patches from upper mentioned bug need further review from native people of many countries.