How to determine which day is the first in week in current locale in C. In Russia monday is the first day, but my mac shows localized calendar with wrong first day. So i wonder if i can determine which day is the first in current locale. Thanks.
anatoly@mb:/Users/anatoly$ cal
Июля 2012
вс пн вт ср чт пт сб
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Apparently on Macs you can use:
Source: [1].
With glibc, you can do:
Remember to call
setlocale()
first. Example:This returns
2
on my system (which means monday ==DAY_2
).Just a note: I don't think it's public API of glibc. However, this is how
locale
tool bundled with it gets first weekday.cal
uses similar method as well.Depending on a particular use, you may be interested in
_NL_TIME_FIRST_WORKDAY
as well.I was wrong in my first post, and ICU provides a C API.
So, if dependency on that library is acceptable for you, you can get the first of the week portably using the following snippet:
Then you link the program with
icu-i18n
pkg-config library.Ah, and they have quite an extensive example printing a calendar, if you might be interested.