]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123017: Add Android to the list of platforms where `strftime` doesn't support...
authorMalcolm Smith <smith@chaquo.com>
Fri, 27 Sep 2024 14:35:18 +0000 (15:35 +0100)
committerGitHub <noreply@github.com>
Fri, 27 Sep 2024 14:35:18 +0000 (10:35 -0400)
Add Android to the list of platforms where `strftime` doesn't support negative years

Lib/test/test_time.py
Misc/NEWS.d/next/Library/2024-09-24-21-15-27.gh-issue-123017.dSAr2f.rst [new file with mode: 0644]
Modules/timemodule.c

index 293799ff68ea05e83b0e9d838ecf0f14ecd353c4..530c317a852e77ba4ffbb87370180eee6695d916 100644 (file)
@@ -654,8 +654,7 @@ class _TestStrftimeYear:
             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:
diff --git a/Misc/NEWS.d/next/Library/2024-09-24-21-15-27.gh-issue-123017.dSAr2f.rst b/Misc/NEWS.d/next/Library/2024-09-24-21-15-27.gh-issue-123017.dSAr2f.rst
new file mode 100644 (file)
index 0000000..45fe478
--- /dev/null
@@ -0,0 +1,2 @@
+Due to unreliable results on some devices, :func:`time.strftime` no longer
+accepts negative years on Android.
index ee59fb73ac1e319ffbe72f252a04d027436fa41f..9720c201a184a850792b735f0d1f15be645c9901 100644 (file)
@@ -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]");