mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #1777412: Remove all limits on tm_year from time.strftime()
The buildbots will tell us which platform does support or not negative years.
This commit is contained in:
parent
af5aee57c9
commit
301f1217ac
2 changed files with 20 additions and 25 deletions
|
@ -294,21 +294,13 @@ class _TestStrftimeYear:
|
||||||
text = self.yearstr(12345)
|
text = self.yearstr(12345)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# strftime() is limited to [1; 9999] with Visual Studio
|
# strftime() is limited to [1; 9999] with Visual Studio
|
||||||
pass
|
return
|
||||||
else:
|
# Issue #10864: OpenIndiana is limited to 4 digits,
|
||||||
# Issue #10864: OpenIndiana is limited to 4 digits, but Python
|
# but Python doesn't raise a ValueError
|
||||||
# doesn't raise a ValueError
|
#self.assertEqual(text, '12345')
|
||||||
#self.assertEqual(text, '12345')
|
#self.assertEqual(self.yearstr(123456789), '123456789')
|
||||||
self.assertIn(text, ('2345', '12345'))
|
self.assertIn(text, ('2345', '12345'))
|
||||||
try:
|
self.assertIn(self.yearstr(123456789), ('123456789', '6789'))
|
||||||
text = self.yearstr(123456789)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
# Issue #10864: OpenIndiana is limited to 4 digits, but Python
|
|
||||||
# doesn't raise a ValueError
|
|
||||||
#self.assertEqual(text, '123456789')
|
|
||||||
self.assertIn(text, ('123456789', '6789'))
|
|
||||||
|
|
||||||
class _Test2dYear(_BaseYearTest):
|
class _Test2dYear(_BaseYearTest):
|
||||||
accept2dyear = 1
|
accept2dyear = 1
|
||||||
|
@ -336,6 +328,17 @@ class _Test4dYear(_BaseYearTest):
|
||||||
self.assertIn(self.yearstr(999), ('999', '0999'))
|
self.assertIn(self.yearstr(999), ('999', '0999'))
|
||||||
self.assertEqual(self.yearstr(9999), '9999')
|
self.assertEqual(self.yearstr(9999), '9999')
|
||||||
|
|
||||||
|
def test_negative(self):
|
||||||
|
try:
|
||||||
|
text = self.yearstr(-1)
|
||||||
|
except ValueError:
|
||||||
|
# strftime() is limited to [1; 9999] with Visual Studio
|
||||||
|
return
|
||||||
|
self.assertIn(text, ('-1', '-001'))
|
||||||
|
|
||||||
|
self.assertEqual(self.yearstr(-1234), '-1234')
|
||||||
|
self.assertEqual(self.yearstr(-123456), '-123456')
|
||||||
|
|
||||||
class TestAsctimeAccept2dYear(_TestAsctimeYear, _Test2dYear):
|
class TestAsctimeAccept2dYear(_TestAsctimeYear, _Test2dYear):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -346,8 +349,7 @@ class TestAsctime4dyear(_TestAsctimeYear, _Test4dYear):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class TestStrftime4dyear(_TestStrftimeYear, _Test4dYear):
|
class TestStrftime4dyear(_TestStrftimeYear, _Test4dYear):
|
||||||
def test_bounds(self):
|
pass
|
||||||
self.assertRaises(ValueError, self.yearstr, 0)
|
|
||||||
|
|
||||||
class Test2dyearBool(_TestAsctimeYear, _Test2dYear):
|
class Test2dyearBool(_TestAsctimeYear, _Test2dYear):
|
||||||
accept2dyear = True
|
accept2dyear = True
|
||||||
|
|
|
@ -332,7 +332,7 @@ gettmarg(PyObject *args, struct tm *p)
|
||||||
if (y < 1000) {
|
if (y < 1000) {
|
||||||
PyObject *accept = PyDict_GetItemString(moddict,
|
PyObject *accept = PyDict_GetItemString(moddict,
|
||||||
"accept2dyear");
|
"accept2dyear");
|
||||||
if (accept != NULL) {
|
if (accept != NULL) {
|
||||||
int acceptval = PyObject_IsTrue(accept);
|
int acceptval = PyObject_IsTrue(accept);
|
||||||
if (acceptval == -1)
|
if (acceptval == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -481,13 +481,6 @@ time_strftime(PyObject *self, PyObject *args)
|
||||||
buf.tm_year + 1900);
|
buf.tm_year + 1900);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (buf.tm_year + 1900 < 1) {
|
|
||||||
PyErr_Format(PyExc_ValueError,
|
|
||||||
"strftime() requires year >= 1",
|
|
||||||
buf.tm_year + 1900);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Normalize tm_isdst just in case someone foolishly implements %Z
|
/* Normalize tm_isdst just in case someone foolishly implements %Z
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue