How to determine the first day of week

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:

  • Run locale first_weekday (by the way, we have to use os.popen here 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:

  • Run locale first_weekday week-1stday
  • Parse week-1stday as date with %Y%m%d
  • Move the result first_weekday - 1 days forward
  • Check the weekday of the result


While 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_weekday=2 and 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.

Happy hamsters

Project Hamster is now part of GNOME! Along with Empathy and some blessed external dependencies. Do not underestimate them however for they are some truly powerful libs including libcanberra, Clutter, Conduit and PolicyKit.

Some new pains are now (temporarily) part of my life. As PH’s father, Toms, is away I am the one responsible for the SVN migration, releasing 2.23.6 and cooperating with i18n and a11y teams. I think we should start by making the stats accessible but I’ll concentrate on moving to GNOME infrastructure for now. Hope the rest of the team gets their SVN accounts up and running soon.

As for Empathy, great stuff. If you like it as much as I do, you can help me convince Xavier to make it a bit prettier and more readable. Hooray for lobbying!

Edit: hamster-applet 2.23.6 is out, following the upcoming GNOME 2.23.6 release.

Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Poland
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Poland.