I'm having an issue with the 'yy' matcher (but not the 'yyyy' matcher) on QDateTime. The code fragment is Python (using PyQt bindings for the Qt application framework), but I assume you can manage any needed translation since the strings and calls are basically the same. FYI the u prefix on u'text' simply forces Python strings to use unicode. Here's my test code:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
date_works_text = u'Monday, 23 April 2012 22:51:41'
date_works_pattern = u'dddd, d MMMM yyyy hh:mm:ss'
date_broken_text = u'Monday, 23 April 12 22:51:41'
date_broken_pattern = u'dddd, d MMMM yy hh:mm:ss'
date_works
= QDateTime.
fromString(date_works_text, date_works_pattern
) date_broken
= QDateTime.
fromString(date_broken_text, date_broken_pattern
)
print date_works.toString()
print date_broken.toString()
from PyQt4.QtGui import *
from PyQt4.QtCore import *
date_works_text = u'Monday, 23 April 2012 22:51:41'
date_works_pattern = u'dddd, d MMMM yyyy hh:mm:ss'
date_broken_text = u'Monday, 23 April 12 22:51:41'
date_broken_pattern = u'dddd, d MMMM yy hh:mm:ss'
date_works = QDateTime.fromString(date_works_text, date_works_pattern)
date_broken = QDateTime.fromString(date_broken_text, date_broken_pattern)
print date_works.toString()
print date_broken.toString()
To copy to clipboard, switch view to plain text mode
The output on my system is:
D:\Users\...>qDateTimeTest.py
Mon Apr 23 22:51:41 2012
<blank line where the second toString() should be>
D:\Users\...>qDateTimeTest.py
Mon Apr 23 22:51:41 2012
<blank line where the second toString() should be>
To copy to clipboard, switch view to plain text mode
It appears to dislike a 'yy' match on '12' even though the pattern is included in the QDateTime format (http://qt-project.org/doc/qt-4.8/qda...tml#fromString)
Am I doing something wrong? If not, can someone confirm that this is a Qt issue (versus PyQt) issue? If you can't reproduce it in Qt, I'll check with the PyQt folks. This just seemed like the right place to start since the alternate 'yyyy' works fine.
Bookmarks