summaryrefslogtreecommitdiff
path: root/Modules/_datetimemodule.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-35066: _dateime.datetime.strftime copies trailing '%' (GH-10692)Miss Islington (bot)2019-01-141-5/+8
| | | | | | | | | | Previously, calling the strftime() method on a datetime object with a trailing '%' in the format string would result in an exception. However, this only occured when the datetime C module was being used; the python implementation did not match this behavior. Datetime is now PEP-399 compliant, and will not throw an exception on a trailing '%'. (cherry picked from commit 454b3d4ea246e8751534e105548d141ed7b0b032) Co-authored-by: MichaelSaah <mike.saah@gmail.com>
* [3.7] bpo-22005: Fixed unpickling instances of datetime classes pickled by ↵Serhiy Storchaka2018-12-071-78/+169
| | | | | | | Python 2. (GH-11017) (GH-11022) encoding='latin1' should be used for successful decoding. (cherry picked from commit 8452ca15f41061c8a6297d7956df22ab476d4df4)
* bpo-35021: Fix assertion failures in _datetimemodule.c. (GH-10039)Miss Islington (bot)2018-11-201-48/+51
| | | | | | | | | | | Fixes assertion failures in _datetimemodule.c introduced in the previous fix (see bpo-31752). Rather of trying to handle an int subclass as exact int, let it to use overridden special methods, but check the result of divmod(). (cherry picked from commit 3ec0f495163da3b7a15deb2805cec48aed432f58) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-35133: Fix mistakes when concatenate string literals on different lines. ↵Miss Islington (bot)2018-11-051-1/+1
| | | | | | | | | | | | (GH-10284) Two kind of mistakes: 1. Missed space. After concatenating there is no space between words. 2. Missed comma. Causes unintentional concatenating in a list of strings. (cherry picked from commit 34fd4c20198dea6ab2fe8dc6d32d744d9bde868d) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-34454: Clean up datetime.fromisoformat surrogate handling (GH-8959)Miss Islington (bot)2018-10-221-72/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Use _PyUnicode_Copy in sanitize_isoformat_str * Use repr in fromisoformat error message This reverses commit 67b74a98b2 per Serhiy Storchaka's suggestion: I suggested to use %R in the error message because including the raw string can be confusing in the case of empty string, or string containing trailing whitespaces, invisible or unprintable characters. We agree that it is better to change both the C and pure Python versions to use repr. * Retain non-sanitized dtstr for error printing This does not create an extra string, it just holds on to a reference to the original input string for purposes of creating the error message. * PEP 7 fixes to from_isoformat * Separate handling of Unicode and other errors In the initial implementation, errors other than encoding errors would both raise an error indicating an invalid format, which would not be true for errors like MemoryError. * Drop needs_decref from _sanitize_isoformat_str Instead _sanitize_isoformat_str returns a new reference, even to the original string. (cherry picked from commit 3df85404d4bf420db3362eeae1345f2cad948a71) Co-authored-by: Paul Ganssle <pganssle@users.noreply.github.com>
* Elaborate datetime.timedelta docstring (GH-7458)Miss Islington (bot)2018-10-191-1/+5
| | | | | (cherry picked from commit d6a61f232619f8a8e6efacc3da5a02abaf25f090) Co-authored-by: Chris Barker <Chris.Barker@noaa.gov>
* closes bpo-34471: _datetime: Add missing NULL check to ↵Miss Islington (bot)2018-08-241-1/+4
| | | | | | | | tzinfo_from_isoformat_results. (GH-8869) Reported by Svace static analyzer. (cherry picked from commit 498845368ff0f6238750ab1d443e7cf4ec98ccd2) Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
* bpo-34454: fix .fromisoformat() methods crashing on inputs with surrogate ↵Miss Islington (bot)2018-08-231-9/+72
| | | | | | | | | | | | | | | | | | | | | | | code points (GH-8862) The current C implementations **crash** if the input includes a surrogate Unicode code point, which is not possible to encode in UTF-8. Important notes: 1. It is possible to pass a non-UTF-8 string as a separator to the `.isoformat()` methods. 2. The pure-Python `datetime.fromisoformat()` implementation accepts strings with a surrogate as the separator. In `datetime.fromisoformat()`, in the special case of non-UTF-8 separators, this implementation will take a performance hit by making a copy of the input string and replacing the separator with 'T'. Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru> Co-authored-by: Paul Ganssle <paul@ganssle.io> (cherry picked from commit 096329f0b2bf5e3f0a16363aa631d993ce078737) Co-authored-by: Paul Ganssle <pganssle@users.noreply.github.com>
* bpo-29097: Forego fold detection on windows for low timestamp values ↵Miss Islington (bot)2018-07-251-1/+16
| | | | | | | | (GH-2385) (GH-8466) On Windows, passing a negative value to local results in an OSError because localtime_s on Windows does not support negative timestamps. Unfortunately this means that fold detection for timestamps between 0 and max_fold_seconds will result in this OSError since we subtract max_fold_seconds from the timestamp to detect a fold. However, since we know there haven't been any folds in the interval [0, max_fold_seconds) in any timezone, we can hackily just forego fold detection for this time range on Windows. (cherry picked from commit 96d1e69a12ed8ab80203277e1abdaf573457a964) Co-authored-by: Ammar Askar <ammar_askar@hotmail.com>
* bpo-33812: Corrected astimezone for naive datetimes. (GH-7578) (GH-7600)Miss Islington (bot)2018-06-101-0/+11
| | | | | | | | | | | | | | | | | | | | | A datetime object d is aware if d.tzinfo is not None and d.tzinfo.utcoffset(d) does not return None. If d.tzinfo is None, or if d.tzinfo is not None but d.tzinfo.utcoffset(d) returns None, d is naive. This commit ensures that instances with non-None d.tzinfo, but d.tzinfo.utcoffset(d) returning None are treated as naive. In addition, C acceleration code will raise TypeError if d.tzinfo.utcoffset(d) returns an object with the type other than timedelta. * Updated the documentation. Assume that the term "naive" is defined elsewhere and remove the not entirely correct clarification. Thanks, Tim. (cherry picked from commit 877b23202b7e7d4f57b58504fd0eb886e8c0b377) Co-authored-by: Alexander Belopolsky <abalkin@users.noreply.github.com>
* [3.7] Fix duplicating words words. (GH-6296) (GH-6297)Serhiy Storchaka2018-03-281-1/+1
| | | | | Most of them have been added in 3.7. (cherry picked from commit bac2d5ba30339298db7d4caa9c8cd31d807cf081)
* [3.7] bpo-32746: Fix multiple typos (GH-5144) (GH-5520)Miss Islington (bot)2018-02-031-1/+1
| | | | | | Fix typos found by codespell in docs, docstrings, and comments. (cherry picked from commit c3d9508ff22ece9a96892b628dd5813e2fb0cd80) Co-authored-by: Leo Arias <leo.arias@canonical.com>
* bpo-10381: Add timezone to datetime C API (#5032)Paul Ganssle2018-01-241-0/+3
| | | | | | | | | | | | | | | | | | * Add timezone to datetime C API * Add documentation for timezone C API macros * Add dedicated tests for datetime type check macros * Remove superfluous C API test * Drop support for TimeZoneType in datetime C API * Expose UTC singleton to the datetime C API * Update datetime C-API documentation to include links * Add reference count information for timezone constructors
* bpo-32403: Faster date and datetime constructors (#4993)Paul Ganssle2018-01-161-45/+75
| | | | | | | | | | | | | | * Add tests for date subclass alternate constructors * Switch over alternate date constructors to fast path * Switch datetime constructors to fastpath, fix bpo-32404 * Add fast path for datetime in date subclass constructor * Set fold in constructor in datetime.combine * Add news entries.
* bpo-29240: Fix locale encodings in UTF-8 Mode (#5170)Victor Stinner2018-01-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Modify locale.localeconv(), time.tzname, os.strerror() and other functions to ignore the UTF-8 Mode: always use the current locale encoding. Changes: * Add _Py_DecodeLocaleEx() and _Py_EncodeLocaleEx(). On decoding or encoding error, they return the position of the error and an error message which are used to raise Unicode errors in PyUnicode_DecodeLocale() and PyUnicode_EncodeLocale(). * Replace _Py_DecodeCurrentLocale() with _Py_DecodeLocaleEx(). * PyUnicode_DecodeLocale() now uses _Py_DecodeLocaleEx() for all cases, especially for the strict error handler. * Add _Py_DecodeUTF8Ex(): return more information on decoding error and supports the strict error handler. * Rename _Py_EncodeUTF8_surrogateescape() to _Py_EncodeUTF8Ex(). * Replace _Py_EncodeCurrentLocale() with _Py_EncodeLocaleEx(). * Ignore the UTF-8 mode to encode/decode localeconv(), strerror() and time zone name. * Remove PyUnicode_DecodeLocale(), PyUnicode_DecodeLocaleAndSize() and PyUnicode_EncodeLocale() now ignore the UTF-8 mode: always use the "current" locale. * Remove _PyUnicode_DecodeCurrentLocale(), _PyUnicode_DecodeCurrentLocaleAndSize() and _PyUnicode_EncodeCurrentLocale().
* bpo-15873: Implement [date][time].fromisoformat (#4699)Paul Ganssle2017-12-211-0/+353
| | | Closes bpo-15873.
* bpo-23699: Use a macro to reduce boilerplate code in rich comparison ↵stratakis2017-11-021-16/+1
| | | | functions (GH-793)
* bpo-31752: Fix possible crash in timedelta constructor called with custom ↵Serhiy Storchaka2017-10-231-2/+7
| | | | | integers. (#3947) Bad remainder in divmod() in intermediate calculations caused an assertion failure.
* Refactor multiplication and division of timedelta and float. (#3656)Serhiy Storchaka2017-10-041-41/+10
| | | Implementations of these operations are virtually identical.
* bpo-31293: Fix crashes in truediv and mul of a timedelta by a float with a ↵Oren Milman2017-09-191-4/+33
| | | | bad as_integer_ratio() method. (#3227)
* bpo-31338 (#3374)Barry Warsaw2017-09-141-2/+1
| | | | | | | * Add Py_UNREACHABLE() as an alias to abort(). * Use Py_UNREACHABLE() instead of assert(0) * Convert more unreachable code to use Py_UNREACHABLE() * Document Py_UNREACHABLE() and a few other macros.
* Closes issue bpo-5288: Allow tzinfo objects with sub-minute offsets. (#2896)Alexander Belopolsky2017-07-311-27/+30
| | | | | | | | | | | | | | | | | | * Closes issue bpo-5288: Allow tzinfo objects with sub-minute offsets. * bpo-5288: Implemented %z formatting of sub-minute offsets. * bpo-5288: Removed mentions of the whole minute limitation on TZ offsets. * bpo-5288: Removed one more mention of the whole minute limitation. Thanks @csabella! * Fix a formatting error in the docs * Addressed review comments. Thanks, @haypo.
* bpo-30302 Make timedelta.__repr__ more informative. (#1493)Utkarsh Upadhyay2017-07-251-15/+44
|
* bpo-29953: Fix memory leaks in the replace() method of datetime and time (#927)Serhiy Storchaka2017-03-311-11/+10
| | | objects when pass out of bound fold argument.
* bpo-29878: Add global instances of int for 0 and 1. (#852)Serhiy Storchaka2017-03-301-5/+3
|
* Merge 3.6Victor Stinner2017-02-101-21/+40
|\
| * Fix datetime.fromtimestamp(): check boundsVictor Stinner2017-02-101-21/+40
| | | | | | | | | | Issue #29100: Fix datetime.fromtimestamp() regression introduced in Python 3.6.0: check minimum and maximum years.
* | Merge 3.6Victor Stinner2017-01-031-5/+5
|\ \ | |/
| * Issue #29140: Fix hash(datetime.time)Victor Stinner2017-01-031-5/+5
| | | | | | | | | | | | Fix time_hash() function: replace DATE_xxx() macros with TIME_xxx() macros. Before, the hash function used a wrong value for microseconds if fold is set (equal to 1).
* | Issue #28959: Added private macro PyDict_GET_SIZE for retrieving the size of ↵Serhiy Storchaka2016-12-161-1/+1
| | | | | | | | dict.
* | Use _PyObject_CallMethodIdObjArgs() in _datetimeVictor Stinner2016-12-091-8/+11
| | | | | | | | | | | | | | | | | | Issue #28915: Replace _PyObject_CallMethodId() with _PyObject_CallMethodIdObjArgs() when the format string was only made of "O" formats, PyObject* arguments. _PyObject_CallMethodIdObjArgs() avoids the creation of a temporary tuple and doesn't have to parse a format string.
* | Fix refleak introduced in change 032cbdb596feVictor Stinner2016-12-091-0/+1
| | | | | | | | Issue #28915.
* | build_struct_time() uses Py_BuildValue()Victor Stinner2016-12-091-11/+20
| | | | | | | | | | | | Issue #28915: Avoid calling _PyObject_CallMethodId() with "(...)" format to avoid the creation of a temporary tuple: use Py_BuildValue() with _PyObject_CallMethodIdObjArgs().
* | Don't parenthesis in _PyObject_CallMethodId() formatVictor Stinner2016-12-091-1/+1
| | | | | | | | | | Issue #28915: Without parenthesis, _PyObject_CallMethodId() avoids the creation a temporary tuple, and so is more efficient.
* | Issue #28752: Restored the __reduce__() methods of datetime objects.Serhiy Storchaka2016-11-221-8/+26
|\ \ | |/
| * Issue #28752: Restored the __reduce__() methods of datetime objects.Serhiy Storchaka2016-11-221-8/+26
| |
* | Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringAndSizeSerhiy Storchaka2016-11-201-2/+2
|\ \ | |/ | | | | with PyUnicode_AsUTF8 and PyUnicode_AsUTF8AndSize.
| * Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringAndSizeSerhiy Storchaka2016-11-201-2/+2
| | | | | | | | with PyUnicode_AsUTF8 and PyUnicode_AsUTF8AndSize.
* | Issue #28511: Use the "U" format instead of "O!" in PyArg_Parse*.Serhiy Storchaka2016-10-231-3/+2
|/
* Issue #28148: Stop using localtime() and gmtime() in the time module.Alexander Belopolsky2016-09-281-51/+16
| | | | | | Introduced platform independent _PyTime_localtime API that is similar to POSIX localtime_r, but available on all platforms. Patch by Ed Schouten.
* stop using Py_LL and Py_ULLBenjamin Peterson2016-09-181-1/+1
|
* #28067: Fixed another typo.Alexander Belopolsky2016-09-101-1/+1
|
* #28067: Fixed a typo.Alexander Belopolsky2016-09-101-1/+1
|
* Closes #28067: Do not call localtime (gmtime) in datetime module.Alexander Belopolsky2016-09-101-42/+60
|
* fix dummy macroBenjamin Peterson2016-09-091-1/+2
|
* replace PY_LONG_LONG with long longBenjamin Peterson2016-09-061-12/+12
|
* Avoid inefficient way to call functions without argumentVictor Stinner2016-09-051-4/+4
| | | | | | Don't pass "()" format to PyObject_CallXXX() to call a function without argument: pass NULL as the format string instead. It avoids to have to parse a string to produce 0 argument.
* Issue #27809: tzinfo_reduce() uses fast callVictor Stinner2016-08-231-14/+10
|
* Closes #27710: Disallow fold not in [0, 1] in time and datetime constructors.Alexander Belopolsky2016-08-081-5/+23
|
* Closes #27661: Added tzinfo keyword argument to datetime.combine.Alexander Belopolsky2016-08-021-16/+20
|