Skip to content

Commit

Permalink
pythongh-123017: Add Android to the list of platforms where `strftime…
Browse files Browse the repository at this point in the history
…` doesn't support negative years (python#124467)

Add Android to the list of platforms where `strftime` doesn't support negative years
  • Loading branch information
mhsmith authored Sep 27, 2024
1 parent 365dffb commit 0a3577b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Lib/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,7 @@ def year4d(y):
self.test_year('%04d', func=year4d)

def skip_if_not_supported(y):
msg = "strftime() is limited to [1; 9999] with Visual Studio"
# Check that it doesn't crash for year > 9999
msg = f"strftime() does not support year {y} on this platform"
try:
time.strftime('%Y', (y,) + (0,) * 8)
except ValueError:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Due to unreliable results on some devices, :func:`time.strftime` no longer
accepts negative years on Android.
7 changes: 6 additions & 1 deletion Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,12 @@ time_strftime(PyObject *module, PyObject *args)
return NULL;
}

#if defined(_MSC_VER) || (defined(__sun) && defined(__SVR4)) || defined(_AIX) || defined(__VXWORKS__)
// Some platforms only support a limited range of years.
//
// Android works with negative years on the emulator, but fails on some
// physical devices (#123017).
#if defined(_MSC_VER) || (defined(__sun) && defined(__SVR4)) || defined(_AIX) \
|| defined(__VXWORKS__) || defined(__ANDROID__)
if (buf.tm_year + 1900 < 1 || 9999 < buf.tm_year + 1900) {
PyErr_SetString(PyExc_ValueError,
"strftime() requires year in [1; 9999]");
Expand Down

0 comments on commit 0a3577b

Please sign in to comment.