wingpanel-indicator-datetime
wingpanel-indicator-datetime copied to clipboard
Model `week_starts_on` doesn't handle Sunday
Prerequisites
- [x] I have searched open and closed issues for duplicates.
Describe the bug
In CalendarModel.vala
, the first day of the week is set from Posix.NLTime.FIRST_WEEKDAY
. The way that it's implemented doesn't work with weeks that start on Sunday (for example, in the US). From what I can tell (I can't find docs on FIRST_WEKDAY
or nl_langinfo(_NL_TIME_FIRST_WEEKDAY)
, which I think is what this actually calls), langinfo
uses Sunday = 1 through Saturday = 7. GLib uses Monday = 1 through Sunday = 7. So the method to subtract 1 from the Posix
call works when the weekday is Monday or later, but Sunday will become 0. This is the enum value of BAD_WEEKDAY
. Instead, it should wrap around to 7.
GNOME Calendar uses another call to WEEK_DAY1
to do this "wrap around" behavior. I've tried to implement this in Vala, but I can't get that value without a segfault, so I'm not sure how to fix this. FWIW, here's their code:
union { unsigned int word; char *string; } langinfo;
gint week_1stday = 0;
gint first_weekday = 1;
guint week_origin;
langinfo.string = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
first_weekday = langinfo.string[0];
langinfo.string = nl_langinfo (_NL_TIME_WEEK_1STDAY);
week_origin = langinfo.word;
if (week_origin == 19971130) /* Sunday */
week_1stday = 0;
else if (week_origin == 19971201) /* Monday */
week_1stday = 1;
else
g_warning ("Unknown value of _NL_TIME_WEEK_1STDAY.\n");
week_start = (week_1stday + first_weekday - 1) % 7;
Platform Information
- [x] I'm using the latest version from git that I've manually compiled
- [ ] I'm using the latest released stable version
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.