Issue1662
Created on 2010-10-04.05:36:45 by proteusguy, last changed 2010-10-16.03:05:46 by zyasoft.
msg6131 (view) |
Author: Ben Scherrey (proteusguy) |
Date: 2010-10-04.05:36:43 |
|
Trying to execute the following code works under c-python but fails
under jython:
import datetime
datetime.datetime.strptime("2010-07-05T09:20:24Z","%Y-%m-%dT%H:%M:%SZ")
results under Jython 2.5.2b1 (Release_2_5_2beta1:7075, Jun 28 2010, 07:44:20):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/jython2.5.2b1/Lib/datetime.py", line 1499, in strptime
return cls(*(_time.strptime(date_string, format))[0:6])
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:783)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:576)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:501)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:476)
at org.python.modules.time.Time.strptime(Time.java:707)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
java.lang.IllegalArgumentException:
java.lang.IllegalArgumentException: Unterminated quote
results under Python 2.6.4 (r264:75706, Jun 16 2010, 19:34:45):
datetime.datetime(2010, 7, 5, 9, 20, 24)
|
msg6135 (view) |
Author: Jim Baker (zyasoft) |
Date: 2010-10-04.13:49:51 |
|
The problem here is that we do the actual parsing with java.text.SimpleDateFormat ( http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html), but Z for that library means parse a RFC 822 timezone (like -0700), not the 'Z' timezone (UTC).
We need to quote 'Z' to fix this bug; we should also quote all other letters not otherwise defined.
|
msg6136 (view) |
Author: Ben Scherrey (proteusguy) |
Date: 2010-10-04.14:53:37 |
|
Thanx for the diagnosis, Jim. Can you suggest a workaround while we wait for a fix in the (hopefully) next release?
|
msg6137 (view) |
Author: Jim Baker (zyasoft) |
Date: 2010-10-04.16:54:44 |
|
The only workaround I have is to omit the Z in the format specifier, since any extra trailing characters are ignored anyway.
So this works:
>>> datetime.datetime.strptime("2010-07-05T09:20:24Z","%Y-%m-%dT%H:%M:%S")
datetime.datetime(2010, 7, 5, 9, 20, 24)
|
msg6138 (view) |
Author: Jim Baker (zyasoft) |
Date: 2010-10-04.17:31:48 |
|
org.python.modules.Time#py2java_format did not properly end the quote if the quoted string literal (in a-z, A-Z) was the last character in the format string.
I have made a fix of this problem in r7133, however, it needs an appropriate unit test to complete. Putting in pending now. As usual, this seems to be underspecified in the Python test suite, including looking at 2.7.
|
msg6172 (view) |
Author: Jim Baker (zyasoft) |
Date: 2010-10-16.03:05:46 |
|
Fixed in r7148. This could use more testing but it does test reasonably throughly the case here, an unterminated quoted literal in the Java format string.
|
|
Date |
User |
Action |
Args |
2010-10-16 03:05:46 | zyasoft | set | status: pending -> closed resolution: accepted -> fixed messages:
+ msg6172 |
2010-10-04 17:31:49 | zyasoft | set | status: open -> pending messages:
+ msg6138 |
2010-10-04 16:54:45 | zyasoft | set | priority: high assignee: zyasoft resolution: accepted messages:
+ msg6137 |
2010-10-04 14:53:38 | proteusguy | set | messages:
+ msg6136 |
2010-10-04 13:51:21 | zyasoft | set | title: datetime.strptime error? -> time.strptime does not use Java date format strings properly |
2010-10-04 13:49:53 | zyasoft | set | nosy:
+ zyasoft messages:
+ msg6135 |
2010-10-04 05:36:45 | proteusguy | create | |
|