[Development] QTBUG-36811. Qml date behaves unexpectedly for negative years.

Ulf Hermann ulf.hermann at theqtcompany.com
Thu Dec 11 13:18:43 CET 2014


> @Ulf Ulf, thank you for pointing at related bug. It seems to me that
> you've already fix the issue, haven't you? Is it correct that the
> solution is to add 1 year to qml date object when the year is less
> than 0?

My solution in https://codereview.qt-project.org/#/c/98065 and https://codereview.qt-project.org/#/c/98174/ works for the common cases, but has some drawbacks. The most important one is that you cannot parse or print any year 0 date in anything but ISO 8601. That may violate section 15.9.5.2 of the ECMAScript standard where it says:

> NOTE For any Date value d whose milliseconds amount is zero, the result of Date.parse(d.toString()) is equal to d.valueOf(). See 15.9.4.2.

With my patches you can construct such a value with year == 0 in ISO 8601, then do toString() on it and get "Invalid Date". This you cannot parse anymore. However, without my changes no negative date re-parses correctly, so it's still an improvement.

Note that the standard does not state any relation between ISO 8601 and any other date format. That is all "implementation-dependent". ISO 8601 certainly has a year 0 and QDate ignores that. But as we don't use QDate for the parsing and generation of ISO 8601 in JS, we should be able to get that right. I'll take another look at the changes.

-- 
Ulf Hermann, Software Engineer | The Qt Company

Digia Germany GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B

Email: ulf.hermann at theqtcompany.com | Mobile: + 49 151 68964561 | Phone: +49 30 63 92 3255 www.qt.io |Qt Blog: http://blog.qt.digia.com/ | Twitter: @QtbyDigia, @Qtproject | Facebook: www.facebook.com/qt



More information about the Development mailing list