This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: no way to determine First weekday (based on locale)
Type: enhancement Stage: commit review
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: IzidorMatusov, ced, eric.araujo, jkkm, lemburg, methane, r.david.murray, tshepang
Priority: normal Keywords: patch

Created on 2013-04-08 08:48 by IzidorMatusov, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
cpython-add-first-day-of-week.diff jkkm, 2013-04-13 19:47 first cut of adding firstdayofweek locale support review
Pull Requests
URL Status Linked Edit
PR 18142 open ced, 2020-01-23 12:12
PR 18327 open methane, 2020-02-03 10:56
Messages (11)
msg186280 - (view) Author: Izidor Matušov (IzidorMatusov) Date: 2013-04-08 08:48
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:
  * http://blogs.gnome.org/patrys/2008/09/29/how-to-determine-the-first-day-of-week/
  * https://github.com/projecthamster/hamster/blob/master/src/hamster/lib/stuff.py#L153
  * http://stackoverflow.com/questions/4265697/how-to-determine-the-first-day-of-week-in-python
msg186380 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-04-09 06:14
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.
msg186384 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-04-09 06:27
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.
msg186698 - (view) Author: Izidor Matušov (IzidorMatusov) Date: 2013-04-13 07:37
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>
locale.localeconv()
Returns the database of the local conventions as a dictionary. This dictionary has the following strings as keys:
</documentation>

However, there is no category for LC_TIME so far.
msg186809 - (view) Author: Kyle McMartin (jkkm) * Date: 2013-04-13 19:47
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.
msg187978 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-04-28 12:59
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.
msg187991 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-04-28 16:01
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.
msg360554 - (view) Author: Cédric Krier (ced) * Date: 2020-01-23 12:29
I submitted https://github.com/python/cpython/pull/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).
I did not keep the nl_langinfo because I do not think it is good to have platform dependent definition.
msg391423 - (view) Author: Cédric Krier (ced) * Date: 2021-04-20 06:52
ping
msg392090 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2021-04-27 15:37
A core dev review is needed to get this feature into 3.10 before the freeze.
msg403408 - (view) Author: Cédric Krier (ced) * Date: 2021-10-07 13:52
I have updated the PR to be included in 3.11
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 61859
2021-10-07 13:52:29cedsetmessages: + msg403408
versions: + Python 3.11, - Python 3.10
2021-04-27 15:37:16eric.araujosetversions: + Python 3.10, - Python 3.9
nosy: + methane

messages: + msg392090

stage: patch review -> commit review
2021-04-20 06:52:37cedsetmessages: + msg391423
2020-02-03 10:56:35methanesetpull_requests: + pull_request17700
2020-01-23 12:29:38cedsetnosy: + ced

messages: + msg360554
versions: + Python 3.9, - Python 3.4
2020-01-23 12:12:14cedsetpull_requests: + pull_request17529
2013-04-28 16:01:00eric.araujosetmessages: + msg187991
2013-04-28 12:59:29r.david.murraysetnosy: + lemburg

messages: + msg187978
stage: needs patch -> patch review
2013-04-13 19:47:22jkkmsetfiles: + cpython-add-first-day-of-week.diff

nosy: + jkkm
messages: + msg186809

keywords: + patch
2013-04-13 07:37:22IzidorMatusovsetmessages: + msg186698
2013-04-12 17:43:43tshepangsetnosy: + tshepang
2013-04-12 17:43:29tshepangsettitle: First weekday -> no way to determine First weekday (based on locale)
2013-04-09 06:27:01r.david.murraysetmessages: + msg186384
2013-04-09 06:14:12eric.araujosetnosy: + eric.araujo
messages: + msg186380
2013-04-08 12:54:09r.david.murraysetnosy: + r.david.murray
stage: needs patch

versions: + Python 3.4
2013-04-08 08:48:03IzidorMatusovcreate