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:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jeff.allen, laurio, pekka.klarck
Priority: normal Keywords:

Created on 2016-06-02.04:59:10 by laurio, last changed 2018-03-03.14:10:31 by jeff.allen.

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.
msg11736 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-03.14:10:31
Our handling of locale is universally weak.
History
Date User Action Args
2018-03-03 14:10:31jeff.allensetpriority: normal
nosy: + jeff.allen
messages: + msg11736
milestone: Jython 2.7.2 ->
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