3

How can I determine what day the week starts with in the current locale? I need this in C, presumably via the <time.h> header. Thanks.

Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166

1 Answers1

0

Locales don't carry that information. That's because what "first day of the week" means depends on the application (on each application), not on the computer.

Where I work, some applications treat Monday as the first day of the week, and others treat Sunday as the first day of the week. Wall calendars here all use Sunday as the first day; manufacturing calendars usually use Monday.


Under Windows, use GetLocaleInfo(), but the locale can be changed at run time. It can be set through the Windows API. GetLocaleInfoEx() has more detailed documentation. It looks like SetLocaleInfo() can change the first day of the week independent of other locale settings.

Under Linux, there are provisions for identifying the first day of the week in the locale utility. (man 5 locale, or locale docs online. Search for "LC_TIME".) It's documented as conforming to POSIX.2, ISO/IEC 14652.

$ locale day
Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday

First day of the week in my locale is Sunday.

I haven't yet been able to find a system call or library call for it. I don't have the source code handy.

Mike Sherrill 'Cat Recall'
  • 91,602
  • 17
  • 122
  • 185
  • 1
    Yes, but countries *do* have information regarding which day is first. It's part of the operating system settings. Surely there's a way of getting at this information with some API? – Dmitri Nesteruk Jul 05 '12 at 22:21
  • @DmitriNesteruk: Which operating system? – Mike Sherrill 'Cat Recall' Jul 05 '12 at 23:26
  • Mac OS 10.7.4 (gah, need 15 chars) – Dmitri Nesteruk Jul 06 '12 at 08:12
  • @Catcall It is very bad that different applications use different "first day of the week", because it is confusing. It should be location or user preference dependent. In country where I live the first day of the week is Monday. When there is an application that fails to recognize this, things can get pretty confusing, especially for non-technical people who might not be familiar with this problem. – Alex Jul 06 '12 at 09:25
  • @Alex: When you have to coordinate manufacturing in multiple countries, you might have to cope with multiple first days of the week. I did. (And multi-national accounting is even worse.) – Mike Sherrill 'Cat Recall' Jul 06 '12 at 21:18