summaryrefslogtreecommitdiffstats
path: root/Modules/timemodule.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-36779: time.tzname returns empty string on Windows if default cod… ↵Miss Islington (bot)2019-06-131-0/+14
| | | | | | | | | | | | | | | | | (GH-13073) Calling setlocale(LC_CTYPE, "") on a system where GetACP() returns CP_UTF8 results in empty strings in _tzname[]. This causes time.tzname to be an empty string. I have reported the bug to the UCRT team and will follow up, but it will take some time get a fix into production. In the meantime one possible workaround is to temporarily change the locale by calling setlocale(LC_CTYPE, "C") before calling _tzset and restore the current locale after if the GetACP() == CP_UTF8 or CP_UTF7 @zooba https://bugs.python.org/issue36779 (cherry picked from commit b4c7defe58695a6670a8fdeaef67a638bbb47e42) Co-authored-by: Paul Monson <paulmon@users.noreply.github.com>
* bpo-24643: Fix "GH-define timezone _timezone" clashes on Windows (GH-12019)Miss Islington (bot)2019-02-261-5/+15
| | | | | (cherry picked from commit 6673decfa0fb078f60587f5cb5e98460eea137c2) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
* bpo-35550: Fix incorrect Solaris define guards (GH-11275)Miss Islington (bot)2018-12-311-2/+2
| | | | | | | | | | Python source code uses on several places ifdef sun or defined(sun) without the underscores, which is not standard compliant and shouldn't be used. Defines should check for __sun instead. Reference: http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_systemGH-Solaris https://bugs.python.org/issue35550 (cherry picked from commit 6f9bc72c79c3262e5d0f2c0e96b016477399cfb1) Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
* bpo-35214: MSan workarounds for socket, time, and test_faulthandler. ↵Miss Islington (bot)2018-12-311-0/+7
| | | | | | | | | | (GH-11375) (GH-11378) Add Clang Memory Sanitizer build instrumentation to work around false positives from the socket and time modules as well as skipping a couple test_faulthandler tests. (cherry picked from commit b474e6774d60fa67d5373e361a0ed53c18b24f53) Co-authored-by: Gregory P. Smith <greg@krypto.org>
* [3.7] bpo-35373: Fix PyInit_timezone() error handling (GH-10864)Victor Stinner2018-12-031-5/+24
| | | | | | | | | | | | | | | | | | * bpo-35373: Fix PyInit_timezone() error handling PyInit_timezone() now returns -1 at exit if an exception is raised. Check also explicitly PyUnicode_DecodeLocale() and Py_BuildValue() errors. * bpo-35373: Fix PyInit_time() error handling (GH-10865) * PyInit_time() now returns NULL if an exception is raised. * Rename PyInit_timezone() to init_timezone(). "PyInit_" prefix is a special prefix for function initializing a module. init_timezone() doesn't initialize a module and the function is not exported. (cherry picked from commit 3bb150d8148e3cc08418077a58f43e064b9fde61)
* get_gmtoff() now returns time_t (GH-10838) (GH-10839)Victor Stinner2018-12-011-9/+29
| | | | | | | | | get_gmtoff() now returns time_t instead of int to fix the following Visual Studio warning: Modules\timemodule.c(1183): warning C4244: 'return': conversion from 'time_t' to 'int', possible loss of data (cherry picked from commit 503ce5c482cb267b0770bc46c315d5cf822bdca9)
* closes bpo-35025: Properly guard the `CLOCK_GETTIME` et al macros in ↵Miss Islington (bot)2018-10-211-0/+4
| | | | | | | | timemodule.c. (GH-9961) Guard the `CLOCK_GETTIME` et al macros in `timemodule` based on the availability of the parent functions (cherry picked from commit 94451182ccd6729c11338926d8a3d11645e86626) Co-authored-by: Max Bélanger <aeromax@gmail.com>
* bpo-34735: Fix a memory leak in Modules/timemodule.c (GH-9418)Miss Islington (bot)2018-09-211-0/+1
| | | | | | There was a missing PyMem_Free(format) in time_strftime(). (cherry picked from commit 91e6c8717b7dcbcc46b189509de5f2d335819f37) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
* bpo-13312: Avoid int underflow in time year. (GH-8912)Miss Islington (bot)2018-08-251-0/+6
| | | | | | Avoids an integer underflow in the time module's year handling code. (cherry picked from commit 76be0fffff8b7dbe649ad4821144461800ffb0d0) Co-authored-by: Gregory P. Smith <greg@krypto.org>
* Fix some warnings produced by different compilers. (GH-5593) (GH-5600)Miss Islington (bot)2018-02-091-0/+2
| | | | | (cherry picked from commit bfe4fd5f2e96e72eecb5b8a0c7df0ac1689f3b7e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-29240: Fix locale encodings in UTF-8 Mode (#5170)Victor Stinner2018-01-151-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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-29240: Ignore UTF-8 Mode in time module (#5148)Victor Stinner2018-01-111-6/+6
| | | | | | time.strftime() must use the current LC_CTYPE encoding, not UTF-8 if the UTF-8 mode is enabled. Add _PyUnicode_DecodeCurrentLocale() function.
* bpo-32025: Add time.thread_time() (#4410)Antoine Pitrou2017-11-151-0/+117
| | | | | | | | | | | | | | * bpo-32025: Add time.thread_time() * Add missing #endif * Add NEWS blurb * Add docs and whatsnew * Address review comments * Review comments
* bpo-31784: Implement PEP 564: add time.time_ns() (#3989)Victor Stinner2017-11-021-117/+309
| | | | | | | | | | | | | | | | | | | | | | | | | Add new time functions: * time.clock_gettime_ns() * time.clock_settime_ns() * time.monotonic_ns() * time.perf_counter_ns() * time.process_time_ns() * time.time_ns() Add new _PyTime functions: * _PyTime_FromTimespec() * _PyTime_FromNanosecondsObject() * _PyTime_FromTimeval() Other changes: * Add also os.times() tests to test_os. * pytime_fromtimeval() and pytime_fromtimeval() now return _PyTime_MAX or _PyTime_MIN on overflow, rather than undefined behaviour * _PyTime_FromNanoseconds() parameter type changes from long long to _PyTime_t
* bpo-31917: Add 3 new clock identifiers (#4207)Victor Stinner2017-11-021-0/+9
| | | | | | | Add new clock identfiers: * time.CLOCK_BOOTTIME * time.CLOCK_PROF * time.CLOCK_UPTIME
* bpo-31806: Use _PyTime_ROUND_TIMEOUT for the timeout argument parsing in ↵Pablo Galindo2017-10-181-1/+1
| | | | | | | | | more functions (#4026) Fix timeout rounding in time.sleep(), threading.Lock.acquire() and socket.socket.settimeout() to round correctly negative timeouts between -1.0 and 0.0. The functions now block waiting for events as expected. Previously, the call was incorrectly non-blocking.
* time.clock() now emits a DeprecationWarning (GH-4020)Victor Stinner2017-10-171-0/+7
| | | | | | | | | | bpo-31803: time.clock() and time.get_clock_info('clock') now emit a DeprecationWarning warning. Replace time.clock() with time.perf_counter() in tests and demos. Remove also hasattr(time, 'monotonic') in test_time since time.monotonic() is now always available since Python 3.5.
* bpo-31773: _PyTime_GetPerfCounter() uses _PyTime_t (GH-3983)Victor Stinner2017-10-161-3/+4
| | | | | | | | * Rewrite win_perf_counter() to only use integers internally. * Add _PyTime_MulDiv() which compute "ticks * mul / div" in two parts (int part and remaining) to prevent integer overflow. * Clock frequency is checked at initialization for integer overflow. * Enhance also pymonotonic() to reduce the precision loss on macOS (mach_absolute_time() clock).
* bpo-31773: time.perf_counter() uses again double (GH-3964)Victor Stinner2017-10-121-17/+11
| | | | | | | | time.clock() and time.perf_counter() now use again C double internally. Remove also _PyTime_GetWinPerfCounterWithInfo(): use _PyTime_GetPerfCounterDoubleWithInfo() instead on Windows.
* bpo-28157: Improvements for the time module documentation (GH-928)Cheryl Sabella2017-10-111-22/+1
| | | | | * Separated functions and constants descriptions in sections. * Added a note about the limitations of timezone constants. * Removed redundant lists from the module docstring.
* bpo-31415: Add _PyTime_GetPerfCounter() and use it for -X importtime (#3936)Victor Stinner2017-10-101-48/+23
| | | | | * Add _PyTime_GetPerfCounter() * Use _PyTime_GetPerfCounter() for -X importtime
* closes bpo-31596: Add an interface for pthread_getcpuclockid(3) (#3756)pdox2017-10-051-0/+32
|
* bpo-28261: Fixed err msgs where PyArg_ParseTuple is used to parse normal ↵Oren Milman2017-08-201-6/+17
| | | | tuples. (#3119)
* timemodule.c: Cast PyUnicode_AsUTF8() to char* (#1294)Victor Stinner2017-04-261-1/+1
| | | | | | | | | | bpo-28769 changed PyUnicode_AsUTF8() return type from const char* to char* in Python 3.7, but tm_zone field type of the tm structure is char* on FreeBSD. Cast PyUnicode_AsUTF8() to char* in gettmarg() to fix the warning: Modules/timemodule.c:443:20: warning: assigning to 'char *' from 'const char *' discards qualifiers
* tmtotuple(): use time_t for gmtoff (#1276)Victor Stinner2017-04-241-3/+3
| | | | | | | timegm() return type is time_t, not int. Use time_t to prevent the following compiler warning on Windows: timemodule.c: warning C4244: '=': conversion from 'time_t' to 'int', possible loss of data
* Only define get_zone() and get_gmtoff() if needed (#1193)Victor Stinner2017-04-201-0/+2
| | | | | | | | | Only define the get_zone() and get_gmtoff() private functions in the time module if these functions are needed to initialize the module. The change fixes the following warnings on AIX: Modules/timemodule.c:1175:1: warning: 'get_gmtoff' defined but not used [-Wunused-function] Modules/timemodule.c:1164:1: warning: 'get_zone' defined but not used [-Wunused-function]
* Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE whereverSerhiy Storchaka2017-01-231-4/+2
| | | | possible. Patch is writen with Coccinelle.
* Fixes maximum usable length of buffer for formatting time zone in localtime().Steve Dower2016-12-141-1/+1
|\
| * Fixes maximum usable length of buffer for formatting time zone in localtime().Steve Dower2016-12-141-1/+1
| |
* | time_strptime() uses PyObject_Call()Victor Stinner2016-12-081-7/+13
|/ | | | | | Issue #28915: Use PyObject_Call() to pass a tuple of positional arguments, instead of relying on _PyObject_CallMethodId() weird behaviour to unpack the tuple.
* Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringAndSizeSerhiy Storchaka2016-11-201-1/+1
| | | | with PyUnicode_AsUTF8 and PyUnicode_AsUTF8AndSize.
* Issue #28148: Stop using localtime() and gmtime() in the time module.Alexander Belopolsky2016-09-281-41/+14
| | | | | | Introduced platform independent _PyTime_localtime API that is similar to POSIX localtime_r, but available on all platforms. Patch by Ed Schouten.
* more granular configure checks for clock_* functions (closes #28081)Benjamin Peterson2016-09-141-3/+11
|
* Closes #25283: Make tm_gmtoff and tm_zone available on all platforms.Alexander Belopolsky2016-09-121-33/+81
|
* Issue #22624: Python 3 requires clock() to buildVictor Stinner2016-07-081-0/+1
|
* Issue #25923: Added more const qualifiers to signatures of static and ↵Serhiy Storchaka2015-12-251-1/+1
| | | | private functions.
* Issue #25923: Added the const qualifier to static constant arrays.Serhiy Storchaka2015-12-251-2/+2
|
* Issue #25092: Fix datetime.strftime() failure when errno was already set to ↵Steve Dower2015-09-221-0/+3
| | | | EINVAL.
* Issue #25029: MemoryError in test_strptimeSteve Dower2015-09-091-13/+7
|
* Issue #24917: time_strftime() buffer over-read.Steve Dower2015-09-071-6/+10
|
* Backing out 09b62202d9b7; the tests fail on Linux, and it needs a re-think.Larry Hastings2015-09-061-12/+0
|
* Issue #24917: time_strftime() Buffer Over-read. Patch by John Leitch.Steve Dower2015-09-051-0/+12
|
* Issue 24244: Prevents termination when an invalid format string is ↵Steve Dower2015-05-221-7/+2
| | | | encountered on Windows.
* PEP 475: on EINTR, retry the function even if the timeout is equals to zeroVictor Stinner2015-03-301-1/+1
| | | | | | | | | Retry: * signal.sigtimedwait() * threading.Lock.acquire() * threading.RLock.acquire() * time.sleep()
* Issue #22117: Replace usage of _PyTime_ROUND_UP with _PyTime_ROUND_CEILINGVictor Stinner2015-03-301-3/+3
| | | | | All these functions only accept positive timeouts, so this change has no effect in practice.
* Issue #22117: Fix usage of _PyTime_AsTimeval()Victor Stinner2015-03-301-4/+1
| | | | | Add _PyTime_AsTimeval_noraise() function. Call it when it's not possible (or not useful) to raise a Python exception on overflow.
* Issue #22117: Add the new _PyTime_ROUND_FLOOR rounding method for the datetimeVictor Stinner2015-03-281-2/+2
| | | | | module. time.clock_settime() now uses this rounding method instead of _PyTime_ROUND_DOWN to handle correctly dates before 1970.
* Issue #22117: Use the _PyTime_t API for time.clock_settime()Victor Stinner2015-03-281-5/+5
| | | | Remove also the now unused _PyTime_AddDouble() function.
* Issue #22117: Write unit tests for _PyTime_AsTimeval()Victor Stinner2015-03-281-1/+4
| | | | | | | * _PyTime_AsTimeval() now ensures that tv_usec is always positive * _PyTime_AsTimespec() now ensures that tv_nsec is always positive * _PyTime_AsTimeval() now returns an integer on overflow instead of raising an exception
* Issue #22117: time.time() now uses the new _PyTime_t APIVictor Stinner2015-03-271-3/+5
| | | | * Add _PyTime_GetSystemClockWithInfo()