Issue2503

classification
Title: datetime.strptime doesn't handle Unicode strings when using sun.locale.formatasdefault=true
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.2
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: laurio, pekka.klarck
Priority: Keywords:

Created on 2016-06-02.04:59:10 by laurio, last changed 2017-01-30.08:16:48 by pekka.klarck.

Messages
msg10863 (view) Author: Lauri Oikarinen (laurio) Date: 2016-06-02.04:59:09
Jython doesn't handle Unicode strings properly when using sun.locale.formatasdefault=true flag. 

Preconditions:
- Window 7, OS language English and regional settings (including date formats) set to Finnish

Steps to reproduce:
- start Jython by "java -Dsun.locale.formatasdefault=true -jar jython-standalone-2.7.0.jar"
- enter to console:
-- from datetime import datetime
-- datetime.strptime('pe tammi 22 14:00:00 2016', u'%a %b %d %H:%M:%S %Y')

Result:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "Z:\Lauri\jython-standalone-2.7.0.jar\Lib\datetime.py", line 1778, in strptime
  File "Z:\Lauri\jython-standalone-2.7.0.jar\Lib\_strptime.py", line 308, in _strptime
  File "Z:\Lauri\jython-standalone-2.7.0.jar\Lib\_strptime.py", line 308, in _strptime
  File "Z:\Lauri\jython-standalone-2.7.0.jar\Lib\_strptime.py", line 265, in compile
  File "Z:\Lauri\jython-standalone-2.7.0.jar\Lib\_strptime.py", line 257, in pattern
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 18: ordinal not in range(128)

After removing the "u" from format-string this issue doesn't reproduce.

Originally happens when using RobotFramwork's DateTime-library and apparently there strings are using Unicode so using this without the "u" is not an option for me.

Related issue in RobotFramework that lead to the discovery that this is Jython bug: https://github.com/robotframework/robotframework/issues/2306
msg11045 (view) Author: Pekka Klärck (pekka.klarck) Date: 2017-01-30.08:16:48
`strptime` with the `%b` directive doesn't seem to work too well on Jython in general.There's also related issue #2285.
History
Date User Action Args
2017-01-30 08:16:48pekka.klarcksetnosy: + pekka.klarck
messages: + msg11045
2016-09-30 16:21:07zyasoftsetmilestone: Jython 2.7.2
2016-06-02 04:59:10lauriocreate