summaryrefslogtreecommitdiffstats
path: root/Modules/_datetimemodule.c
Commit message (Collapse)AuthorAgeFilesLines
* Clarify distinction between datetime module and class in deprecation ↵Clément Robert2023-08-271-4/+4
| | | | messages (GH-108073)
* gh-108444: Replace _PyLong_AsInt() with PyLong_AsInt() (#108459)Victor Stinner2023-08-241-3/+3
| | | | | | Change generated by the command: sed -i -e 's!_PyLong_AsInt!PyLong_AsInt!g' \ $(find -name "*.c" -o -name "*.h")
* gh-106869: Use new PyMemberDef constant names (#106871)Victor Stinner2023-07-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
* gh-86493: Modernize modules initialization code (GH-106858)Serhiy Storchaka2023-07-251-2/+1
| | | | | Use PyModule_Add() or PyModule_AddObjectRef() instead of soft deprecated PyModule_AddObject().
* gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)Serhiy Storchaka2023-07-121-1/+1
|
* gh-105375: Harden _datetime initialisation (#105604)Erlend E. Aasland2023-06-111-5/+30
| | | Improve error handling so init bails on the first exception.
* gh-92536: Remove PyUnicode_READY() calls (#105210)Victor Stinner2023-06-011-9/+0
| | | | Since Python 3.12, PyUnicode_READY() does nothing and always returns 0.
* gh-103857: Document utcnow and utcfromtimestamp deprecations in What's New ↵Hugo van Kemenade2023-05-211-1/+1
| | | | | | (#104542) Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
* gh-103857: Update deprecation stacktrace to point to calling line (#104431)Hugo van Kemenade2023-05-121-2/+2
|
* GH-103944: Check error status when raising DeprecationWarning (#103949)Paul Ganssle2023-04-281-12/+12
|
* GH-103857: Deprecate utcnow and utcfromtimestamp (#103858)Paul Ganssle2023-04-271-0/+14
| | | | | Using `datetime.datetime.utcnow()` and `datetime.datetime.utcfromtimestamp()` will now raise a `DeprecationWarning`. We also have removed our internal uses of these functions and documented the change.
* gh-83861: Fix datetime.astimezone() method (GH-101545)Alexander Belopolsky2023-04-191-2/+16
|
* gh-99537: Use Py_SETREF(var, NULL) in C code (#99687)Victor Stinner2022-11-231-8/+4
| | | Replace "Py_DECREF(var); var = NULL;" with "Py_SETREF(var, NULL);".
* gh-99537: Use Py_SETREF() function in C code (#99656)Victor Stinner2022-11-221-6/+2
| | | | | | | | | | | | | | | Fix potential race condition in code patterns: * Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);" * Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);" * Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);" Other changes: * Replace "old = var; var = new; Py_DECREF(var)" with "Py_SETREF(var, new);" * Replace "old = var; var = new; Py_XDECREF(var)" with "Py_XSETREF(var, new);" * And remove the "old" variable.
* gh-99300: Use Py_NewRef() in Modules/_datetimemodule.c (#99465)Victor Stinner2022-11-141-67/+34
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in Modules/_datetimemodule.c and Modules/_zoneinfo.c
* GH-90699: Remove remaining `_Py_IDENTIFIER` stdlib usage (GH-99067)Kumar Aditya2022-11-071-29/+27
|
* gh-69142: add %:z strftime format code (gh-95983)TW2022-08-281-22/+42
| | | | | | | | | | | | | | | | datetime.isoformat generates the tzoffset with colons, but there was no format code to make strftime output the same format. for simplicity and consistency the %:z formatting behaves mostly as %z, with the exception of adding colons. this includes the dynamic behaviour of adding seconds and microseconds only when needed (when not 0). this fixes the still open "generate" part of this issue: https://github.com/python/cpython/issues/69142 Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* gh-91838: Resolve HTTP links which redirect to HTTPS (GH-95642)Serhiy Storchaka2022-08-041-1/+1
| | | | It updates links which redirect to HTTPS with different authority or path.
* gh-93741: Add private C API _PyImport_GetModuleAttrString() (GH-93742)Serhiy Storchaka2022-06-141-23/+11
| | | | | | It combines PyImport_ImportModule() and PyObject_GetAttrString() and saves 4-6 lines of code on every use. Add also _PyImport_GetModuleAttr() which takes Python strings as arguments.
* gh-89653: Use int type for Unicode kind (#92704)Victor Stinner2022-05-131-1/+1
| | | | Use the same type that PyUnicode_FromKindAndData() kind parameter type (public C API): int.
* Check result of utc_to_seconds and skip fold probe in pure Python (#91582)Paul Ganssle2022-05-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `utc_to_seconds` call can fail, here's a minimal reproducer on Linux: TZ=UTC python -c "from datetime import *; datetime.fromtimestamp(253402300799 + 1)" The old behavior still raised an error in a similar way, but only because subsequent calculations happened to fail as well. Better to fail fast. This also refactors the tests to split out the `fromtimestamp` and `utcfromtimestamp` tests, and to get us closer to the actual desired limits of the functions. As part of this, we also changed the way we detect platforms where the same limits don't necessarily apply (e.g. Windows). As part of refactoring the tests to hit this condition explicitly (even though the user-facing behvior doesn't change in any way we plan to guarantee), I noticed that there was a difference in the places that `datetime.utcfromtimestamp` fails in the C and pure Python versions, which was fixed by skipping the "probe for fold" logic for UTC specifically — since UTC doesn't have any folds or gaps, we were never going to find a fold value anyway. This should prevent some failures in the pure python `utcfromtimestamp` method on timestamps close to 0001-01-01. There are two separate news entries for this because one is a potentially user-facing change, the other is an internal code correctness change that, if anything, changes some error messages. The two happen to be coupled because of the test refactoring, but they are probably best thought of as independent changes. Fixes GH-91581
* gh-80010: Expand fromisoformat to include most of ISO-8601 (#92177)Paul Ganssle2022-05-061-71/+288
| | | This expands `fromisoformat` to cover most of the common uses of ISO 8601. We may expand the scope more in the future.
* gh-91928: Add `datetime.UTC` alias for `datetime.timezone.utc` (GH-91973)Kabir Kwatra2022-05-031-0/+4
| | | | | | | | | ### fixes #91928 `UTC` is now module attribute aliased to `datetime.timezone.utc`. You can now do the following: ```python from datetime import UTC ```
* gh-91320: Use _PyCFunction_CAST() (#92251)Victor Stinner2022-05-031-11/+11
| | | | | | | | | | Replace "(PyCFunction)(void(*)(void))func" cast with _PyCFunction_CAST(func). Change generated by the command: sed -i -e \ 's!(PyCFunction)(void(\*)(void)) *\([A-Za-z0-9_]\+\)!_PyCFunction_CAST(\1)!g' \ $(find -name "*.c")
* gh-91731: Replace Py_BUILD_ASSERT() with static_assert() (#91730)Victor Stinner2022-04-201-3/+3
| | | | | | | | | | | | Python 3.11 now uses C11 standard which adds static_assert() to <assert.h>. * In pytime.c, replace Py_BUILD_ASSERT() with preprocessor checks on SIZEOF_TIME_T with #error. * On macOS, py_mach_timebase_info() now accepts timebase members with the same size than _PyTime_t. * py_get_monotonic_clock() now saturates GetTickCount64() to _PyTime_MAX: GetTickCount64() is unsigned, whereas _PyTime_t is signed.
* bpo-26579: Add object.__getstate__(). (GH-2821)Serhiy Storchaka2022-04-061-26/+4
| | | | | | | Copying and pickling instances of subclasses of builtin types bytearray, set, frozenset, collections.OrderedDict, collections.deque, weakref.WeakSet, and datetime.tzinfo now copies and pickles instance attributes implemented as slots.
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | global objects. (gh-30928) We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
* bpo-45855: Replaced deprecated `PyImport_ImportModuleNoBlock` with ↵Kumar Aditya2021-12-121-4/+4
| | | | PyImport_ImportModule (GH-30046)
* bpo-43974: Move Py_BUILD_CORE_MODULE into module code (GH-29157)Christian Heimes2021-10-221-0/+4
| | | | | | | | | | | | | | setup.py no longer defines Py_BUILD_CORE_MODULE. Instead every module defines the macro before #include "Python.h" unless Py_BUILD_CORE_BUILTIN is already defined. Py_BUILD_CORE_BUILTIN is defined for every module that is built by Modules/Setup. The PR also simplifies Modules/Setup. Makefile and makesetup already define Py_BUILD_CORE_BUILTIN and include Modules/internal for us. Signed-off-by: Christian Heimes <christian@python.org>
* [codemod] Fix non-matching bracket pairs (GH-28473)Mohamad Mansour2021-09-211-1/+1
| | | | | Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-41798: Allocate the _datetime.datetime_CAPI on the heap memory (GH-24096)Hai Shi2021-01-061-21/+43
|
* bpo-1635741: Enhance _datetime error handling (GH-23139)Mohamed Koubaa2020-11-201-117/+103
|
* bpo-42161: Modules/ uses _PyLong_GetZero() and _PyLong_GetOne() (GH-22998)Victor Stinner2020-10-271-2/+3
| | | | | | Use _PyLong_GetZero() and _PyLong_GetOne() in Modules/ directory. _cursesmodule.c and zoneinfo.c are now built with Py_BUILD_CORE_MODULE macro defined.
* bpo-41867: List options for timespec in docstrings of isoformat methods ↵Ram Rachum2020-10-031-4/+8
| | | | (GH-22418)
* bpo-30155: Add macros to get tzinfo from datetime instances (GH-21633)Zackery Spytz2020-09-231-8/+3
| | | | Add PyDateTime_DATE_GET_TZINFO() and PyDateTime_TIME_GET_TZINFO() macros.
* bpo-40989: PyObject_INIT() becomes an alias to PyObject_Init() (GH-20901)Victor Stinner2020-06-151-18/+13
| | | | | | | | | | | | | | The PyObject_INIT() and PyObject_INIT_VAR() macros become aliases to, respectively, PyObject_Init() and PyObject_InitVar() functions. Rename _PyObject_INIT() and _PyObject_INIT_VAR() static inline functions to, respectively, _PyObject_Init() and _PyObject_InitVar(), and move them to pycore_object.h. Remove their return value: their return type becomes void. The _datetime module is now built with the Py_BUILD_CORE_MODULE macro defined. Remove an outdated comment on _Py_tracemalloc_config.
* bpo-40777: Initialize PyDateTime_IsoCalendarDateType.tp_base at run-time ↵Petr Viktorin2020-05-281-3/+10
| | | | | | | (GH-20493) Recent changes to _datetimemodule broke compilation on mingw; see the comments in this change for details. FWIW, @corona10: this issue is why `PyType_FromModuleAndSpec` & friends take the `bases` argument at run time.
* bpo-24416: Return named tuple from date.isocalendar() (GH-20113)Paul Ganssle2020-05-161-4/+148
| | | | | | | | | | | | | | | | | | | | | | | {date, datetime}.isocalendar() now return a private custom named tuple object IsoCalendarDate rather than a simple tuple. In order to leave IsocalendarDate as a private class and to improve what backwards compatibility is offered for pickling the result of a datetime.isocalendar() call, add a __reduce__ method to the named tuples that reduces them to plain tuples. (This is the part of this PR most likely to cause problems — if it causes major issues, switching to a strucseq or equivalent would be prudent). The pure python implementation of IsoCalendarDate uses positional-only arguments, since it is private and only constructed by position anyway; the equivalent change in the argument clinic on the C side would require us to move the forward declaration of the type above the clinic import for whatever reason, so it seems preferable to hold off on that for now. bpo-24416: https://bugs.python.org/issue24416 Original PR by Dong-hee Na with only minor alterations by Paul Ganssle. Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
* bpo-40268: Remove unused structmember.h includes (GH-19530)Victor Stinner2020-04-151-1/+1
| | | | | | If only offsetof() is needed: include stddef.h instead. When structmember.h is used, add a comment explaining that PyMemberDef is used.
* bpo-40024: Update C extension modules to use PyModule_AddType() (GH-19119)Dong-hee Na2020-03-241-31/+14
| | | | | | Update _asyncio, _bz2, _csv, _curses, _datetime, _io, _operator, _pickle, _queue, blake2, multibytecodec and overlapped C extension modules to use PyModule_AddType().
* closes bpo-39736: const strings in Modules/_datetimemodule.c and ↵Andy Lester2020-02-241-3/+3
| | | | Modules/_testbuffer.c (GH-18637)
* bpo-39573: Clean up modules and headers to use Py_IS_TYPE() function (GH-18521)Dong-hee Na2020-02-171-5/+5
|
* bpo-39573: Use Py_TYPE() macro in Modules directory (GH-18393)Victor Stinner2020-02-071-1/+1
| | | Replace direct access to PyObject.ob_type with Py_TYPE().
* bpo-39237, datetime: Remove redundant call to round from delta_new (GH-17877)Alex Henrie2020-01-081-1/+0
|
* bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630)Serhiy Storchaka2019-09-011-11/+10
| | | Only AttributeError should be silenced.
* bpo-37372: Fix error unpickling datetime.time objects from Python 2 with ↵Justin Blanchard2019-08-291-1/+1
| | | | seconds>=24. (GH-14307)
* bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390)Pablo Galindo2019-08-221-1/+2
| | | | | | | https://bugs.python.org/issue37915 Automerge-Triggered-By: @pablogsal
* bpo-37642: Update acceptable offsets in timezone (GH-14878)Ngalim Siregar2019-08-091-2/+9
| | | | | | | | | This fixes an inconsistency between the Python and C implementations of the datetime module. The pure python version of the code was not accepting offsets greater than 23:59 but less than 24:00. This is an accidental legacy of the original implementation, which was put in place before tzinfo allowed sub-minute time zone offsets. GH-14878
* bpo-37685: Fixed comparisons of datetime.timedelta and datetime.timezone. ↵Serhiy Storchaka2019-08-041-5/+2
| | | | | | | | | (GH-14996) There was a discrepancy between the Python and C implementations. Add singletons ALWAYS_EQ, LARGEST and SMALLEST in test.support to test mixed type comparison.
* bpo-37547: add _PyObject_CallMethodOneArg (GH-14685)Jeroen Demeyer2019-07-111-9/+6
|