[Jython-checkins] jython: Fixes #1964 time.strptime() now supports %f in format.
jeff.allen
jython-checkins at python.org
Mon Dec 2 21:31:05 CET 2013
http://hg.python.org/jython/rev/b31e71644fa8
changeset: 7167:b31e71644fa8
user: Santoso Wijaya <santoso.wijaya at gmail.com>
date: Mon Dec 02 08:25:56 2013 +0000
summary:
Fixes #1964 time.strptime() now supports %f in format.
Change to modules.Time to revert to Python implementation if %f seen, and to map
IllegalArgumentException to ValueError along line suggested by arfrever. Unit
tests for both.
files:
Lib/test/test_strptime_jy.py | 9 +++++++++
NEWS | 1 +
src/org/python/modules/time/Time.java | 8 +++++++-
3 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_strptime_jy.py b/Lib/test/test_strptime_jy.py
--- a/Lib/test/test_strptime_jy.py
+++ b/Lib/test/test_strptime_jy.py
@@ -2,6 +2,7 @@
import unittest
from datetime import datetime
+from time import strptime
from test import test_support
@@ -13,6 +14,14 @@
# tests bug 1662
self.assertEqual(now, datetime.strptime(now.isoformat('T') + 'Z', "%Y-%m-%dT%H:%M:%SZ"))
+ def test_IllegalArgument_to_ValueError(self):
+ with self.assertRaises(ValueError):
+ d = strptime('', '%e')
+
+ def test_issue1964(self):
+ d = strptime('0', '%f')
+ self.assertEqual(0, d[1])
+
def test_main():
test_support.run_unittest(
ParsingTests
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@
- [ 2020 ] str.translate should delete characters in the second arg when table is None
- [ 1753 ] zlib doesn't call end() on compress and decompress
- [ 1860 ] test failures in test_array.py
+ - [ 1964 ] time.strptime() does not support %f in format
- [ 2033 ] test_strptime fails: test_mar1_comes_after_feb29_even_when_omitting_the_year
- [ 2046 ] sys.stdin.readline() hangs when used interactively (JLine, Windows)
- [ 2060 ] Thread ident missing
diff --git a/src/org/python/modules/time/Time.java b/src/org/python/modules/time/Time.java
--- a/src/org/python/modules/time/Time.java
+++ b/src/org/python/modules/time/Time.java
@@ -704,7 +704,12 @@
// Format not translatable to java, fallback to _strptime
return pystrptime(data_string, format);
}
- SimpleDateFormat d = new SimpleDateFormat(jformat);
+ SimpleDateFormat d = null;
+ try {
+ d = new SimpleDateFormat(jformat);
+ } catch (IllegalArgumentException e) {
+ throwValueError(e.getLocalizedMessage());
+ }
Calendar cal = Calendar.getInstance();
try {
cal.setTime(d.parse(data_string));
@@ -746,6 +751,7 @@
// strptime formats not supported by SimpleDateFormat:
private static final List<Character> notSupported = new ArrayList<Character>() {{
add('w');
+ add('f');
}};
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list