New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no way to determine First weekday (based on locale) #61859
Comments
There is no way how to figure out the first weekday: Does a week start with Monday or Saturday? (Or any other day?) According to documentation, module locale doesn't provide this information. Module calendar uses European convention (Monday is the first weekday). Purpose of this issue is to have a way how to return first weekday (Monday, Sunday, etc) Known workarounds: |
I’m not sure I understand the request. Is it that you want to know if you should e.g. display a calendar with Monday or Sunday in the first column depending on the user country? It looks like this could belong in the locale or calendar module, if there is a clear 1:1 mapping of locale to first week day (the links you gave seem to indicate that there is one). I think a new API should allow people to pass the locale explicitly: for example, I may want to read something in English, but having the Monday as first weekday makes calendars much easier to understand for me. |
I believe the request is exactly a function in the locale module to expose the locale-dependent calendar-week-start-day information based on the algorithm in the linked articles. As for being able to pass in the locale, that's a general problem with the current locale API, and probably should be fixed as part of a general API enhancement, rather than special casing this one new function. |
Yes, I need to find out calendar-week-start-day information based on the current locale. Or in the other words, I need to find out what the correct parameter for calendar.Calendar([firstweekday]) object is. With locale en_US it should be Sunday, with locale sk_SK it should be Monday, and so on. I guess it could be find out from LC_TIME locale. There is already API for such small bits of information: <documentation> However, there is no category for LC_TIME so far. |
Hacky patch at adding support for querying these values from nl_langinfo, and a new exported function from the locale module to return a guess at the first day of the week appropriate for Calendar.firstdayofweek After writing this, I think it might be better to implement this as another hash, so keys can be queried and objects directly returned. I'll take a look at that approach soon. Of course, all this is contingent on having support from libc, and it seems only Linux currently has this, and the *BSDs (and hence OS X via FreeBSD) do not. I'll look into that as well. |
Thanks for the patch. We'll be interested in the results of your research, certainly. Windows support would also be a question we'd probably want to consider before deciding whether or not to add this. I've added MAL as nosy since I suspect he'll have thoughts about the API, as well as the appropriateness of the feature. |
If I read the patch correctly, the code can return 0 if Monday is the first weekday as indicated by glibc, or as a fallback. I think there should be a difference. |
I submitted #18142 which implements (based on the initial patch) a function locale.getfirstweekday(). The implementation supports glibc (if _NL_TIME_FIRST_WEEKDAY is defined) and Windows (not yet tested). |
ping |
A core dev review is needed to get this feature into 3.10 before the freeze. |
I have updated the PR to be included in 3.11 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: