-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-17659: Add locale.getfirstweekday #18142
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
Open
cedk
wants to merge
35
commits into
python:main
Choose a base branch
from
cedk:locale-first-weekday
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
db86bbd
bpo-17659: Add locale.getfirstweekday
cedk 7adec3b
Use French as testing local on Windows
cedk 149e981
Skip fr_FR test on windows platform
cedk 53d1617
Use BaseLocalizedTest class to test getfirstweekday
cedk 45f60ce
Use links in news
cedk 128512f
Use PyLong_FromLong instead of Py_BuildValue
cedk c5227db
Add missing args agument
cedk ca91d71
Merge branch 'master' into locale-first-weekday
cedk 0fc147f
Update versionadded
cedk fcb49ed
Set only LC_TIME for test
cedk e2d62f1
Restore original aclocal.m4
cedk bd1c7de
Merge branch 'main' of https://github.com/python/cpython into locale-…
cedk 727d186
Update versionadded
cedk 1ba7c75
Return None if unknown
cedk dc6e26a
Merge branch 'main' into locale-first-weekday
cedk df2b213
Correctly test if start is between 0 and 6
cedk 6503b65
Return None instead of NULL
cedk 6f6b9a4
Fix conversion of windows value
cedk dd5125c
Default first day of the week on Windows is Sunday
cedk c898b18
Do not test fallback on glibc
cedk 050f04f
Fix indentation
cedk 351add0
Merge branch 'main' into locale-first-weekday
cedk d65d016
autoreconf
cedk 3afd7f4
Use aclocal 1.16.3
cedk aff2d86
Remove unrelated change from generated files
cedk bff7081
Fix serial
cedk 06e4b07
Simplify preprocessor clause
cedk b46ccf5
Fix ac usage
cedk 7481abe
Replace test by AS_VAR_IF
cedk af18d0a
Fix usage of AC_CACHE_CHECK
cedk 5774de6
Add comment about magic constant
cedk eb6629d
Restore missing define of _NL_TIME_FIRST_WEEKDAY
cedk b4c59e3
Use AS_VAR_IF
cedk d04795a
Return None for unknown week_1stday
cedk fadf91e
Keep default week_1stday as Sunday
cedk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2020-01-23-13-05-44.bpo-17659.UfyH00.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Provide a :func:`locale.getfirstweekday()` function, which returns the integer | ||
of the first day of week. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -623,6 +623,45 @@ _locale_nl_langinfo_impl(PyObject *module, int item) | |
} | ||
#endif /* HAVE_LANGINFO_H */ | ||
|
||
PyDoc_STRVAR(getfirstweekday__doc__, | ||
"getfirstweekday() -> integer\n" | ||
"Return the first day of week. 0 is Monday, 6 is Sunday and None is unknown"); | ||
|
||
static PyObject* | ||
PyLocale_getfirstweekday(PyObject* self, PyObject* args) | ||
{ | ||
int start = -1; | ||
#if defined(MS_WINDOWS) | ||
char locale[1]; | ||
|
||
if (!GetLocaleInfo(LOCALE_USER_DEFAULT, | ||
LOCALE_IFIRSTDAYOFWEEK, | ||
locale, sizeof(locale))) { | ||
start = (locale[0] - '0') % 7; | ||
} | ||
#elif defined(HAVE__NL_TIME_FIRST_WEEKDAY) | ||
int first_weekday = nl_langinfo(_NL_TIME_FIRST_WEEKDAY)[0]; | ||
long week_1stday = (long)nl_langinfo(_NL_TIME_WEEK_1STDAY); | ||
/* Magic constant is defined by glibc as the third value of the week | ||
* keyword of LC_TIME */ | ||
switch (week_1stday) { | ||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed it seems that some version of glibc under en_US does not return one of the two values. |
||
case 19971130: | ||
cedk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
week_1stday = 0; | ||
break; | ||
case 19971201: | ||
week_1stday = 1; | ||
break; | ||
} | ||
start = (week_1stday + first_weekday - 1) % 7; | ||
#endif | ||
if (0 <= start && start <= 6) { | ||
return PyLong_FromLong(start); | ||
} else { | ||
Py_RETURN_NONE; | ||
} | ||
} | ||
|
||
#ifdef HAVE_LIBINTL_H | ||
|
||
/*[clinic input] | ||
|
@@ -801,6 +840,8 @@ static struct PyMethodDef PyLocale_Methods[] = { | |
#ifdef HAVE_LANGINFO_H | ||
_LOCALE_NL_LANGINFO_METHODDEF | ||
#endif | ||
{"getfirstweekday", (PyCFunction) PyLocale_getfirstweekday, | ||
METH_NOARGS, getfirstweekday__doc__}, | ||
#ifdef HAVE_LIBINTL_H | ||
_LOCALE_GETTEXT_METHODDEF | ||
_LOCALE_DGETTEXT_METHODDEF | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you verified that the test passes on musl libc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not have access to such system.