Today we got a report for bug #554256 in Hamster. The first day of week was reported as Sunday for some locales that certainly used Monday. I did some research and found that before Hamster relied on a simple check to determine the result:
locale first_weekday(by the way, we have to use
os.popenhere as these don’t seem to be accessible from Python)
- If the result is 1, use Sunday, else use Monday (literally, it would treat 2 and 6 as Monday)
That seemed to work at least for some countries but was wrong which became apparent when more people started using Hamster (and to put myself in shame: I didn’t notice this before but it was also broken for me). It seems the correct version is:
locale first_weekday week-1stday
week-1stdayas date with
- Move the result
first_weekday - 1days forward
- Check the weekday of the result
locale manual pages are horribly outdated, all web searches point to
week-1stday as the beginning of the first week of tracked Unix time.
first_weekday is the 1-based offset of that week’s start day. It seems it’s only there so you can specify
first_workday=1 for the rare cases where working days span across two weeks.
Please do correct me if this is wrong as all of the above are assumptions based on glibc code and Google results. Hope the above helps someone in the future.
Update: vuntz was kind enough to point me to
gtkcalendar.c, part of GTK+. It does the same thing described above so it seems the method is correct.