Skip to content
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

Open
IzidorMatusov mannequin opened this issue Apr 8, 2013 · 11 comments
Open

no way to determine First weekday (based on locale) #61859

IzidorMatusov mannequin opened this issue Apr 8, 2013 · 11 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@IzidorMatusov
Copy link
Mannequin

IzidorMatusov mannequin commented Apr 8, 2013

BPO 17659
Nosy @malemburg, @merwok, @cedk, @bitdancer, @methane
PRs
  • bpo-17659: Add locale.getfirstweekday #18142
  • bpo-39087: Optimize PyUnicode_AsUTF8AndSize(). #18327
  • Files
  • cpython-add-first-day-of-week.diff: first cut of adding firstdayofweek locale support
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2013-04-08.08:48:03.619>
    labels = ['type-feature', 'library', '3.11']
    title = 'no way to determine First weekday (based on locale)'
    updated_at = <Date 2021-10-07.13:52:29.432>
    user = 'https://bugs.python.org/IzidorMatusov'

    bugs.python.org fields:

    activity = <Date 2021-10-07.13:52:29.432>
    actor = 'ced'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2013-04-08.08:48:03.619>
    creator = 'IzidorMatusov'
    dependencies = []
    files = ['29819']
    hgrepos = []
    issue_num = 17659
    keywords = ['patch']
    message_count = 11.0
    messages = ['186280', '186380', '186384', '186698', '186809', '187978', '187991', '360554', '391423', '392090', '403408']
    nosy_count = 8.0
    nosy_names = ['lemburg', 'eric.araujo', 'ced', 'r.david.murray', 'methane', 'tshepang', 'jkkm', 'IzidorMatusov']
    pr_nums = ['18142', '18327']
    priority = 'normal'
    resolution = None
    stage = 'commit review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue17659'
    versions = ['Python 3.11']

    @IzidorMatusov
    Copy link
    Mannequin Author

    IzidorMatusov mannequin commented Apr 8, 2013

    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:

    @IzidorMatusov IzidorMatusov mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Apr 8, 2013
    @merwok
    Copy link
    Member

    merwok commented Apr 9, 2013

    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.

    @bitdancer
    Copy link
    Member

    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.

    @tshepang tshepang mannequin changed the title First weekday no way to determine First weekday (based on locale) Apr 12, 2013
    @IzidorMatusov
    Copy link
    Mannequin Author

    IzidorMatusov mannequin commented Apr 13, 2013

    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.

    @jkkm
    Copy link
    Mannequin

    jkkm mannequin commented Apr 13, 2013

    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.

    @bitdancer
    Copy link
    Member

    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.

    @merwok
    Copy link
    Member

    merwok commented Apr 28, 2013

    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.

    @cedk
    Copy link
    Mannequin

    cedk mannequin commented Jan 23, 2020

    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).
    I did not keep the nl_langinfo because I do not think it is good to have platform dependent definition.

    @cedk cedk mannequin added the 3.9 only security fixes label Jan 23, 2020
    @cedk
    Copy link
    Mannequin

    cedk mannequin commented Apr 20, 2021

    ping

    @merwok
    Copy link
    Member

    merwok commented Apr 27, 2021

    A core dev review is needed to get this feature into 3.10 before the freeze.

    @merwok merwok added 3.10 only security fixes and removed 3.9 only security fixes labels Apr 27, 2021
    @cedk
    Copy link
    Mannequin

    cedk mannequin commented Oct 7, 2021

    I have updated the PR to be included in 3.11

    @cedk cedk mannequin added 3.11 only security fixes and removed 3.10 only security fixes labels Oct 7, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    Status: No status
    Development

    No branches or pull requests

    2 participants