Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.9.6
-
None
-
-
ced34cb3d5805f1fbaf3b275714a1a5f3585900c (qt/qtbase/5.11)
Description
When creating a QDateTime object using ::fromString if the date is in the daylight saving time change the object may not be valid (as isValid() sees or toString() fails).
To better understand I made a small example also attached (x.cpp).
#include <iostream> #include <QtCore/QDateTime> int main (int ac, char **av) { QString tmp("2008.10.19"); QDateTime ts = QDateTime::fromString(tmp, "yyyy.MM.dd"); std::cout << "Date: " << ts.toString("dd.MM.yyyy hh.mm").toStdString() << std::endl; std::cout << "From epoch (ms): " << ts.toMSecsSinceEpoch() << std::endl; std::cout << "Valid: " << ts.isValid() << std::endl; }
If this code is called with a TZ='Brazil/East' it will output:
$ TZ='Brazil/East' ./x Date: From epoch (ms): 1224385200000 Valid: 0
If called with a TZ='GMT' it will output:
$ TZ='GMT' ./x Date: 19.10.2008 00.00 From epoch (ms): 1224374400000 Valid: 1
I don't know if this is expected behavior for this code, but it seems the QDateTime should generate a valid object since it didn't receive time values, only date (yyyy.MM.dd), also on both timezones the ms from epoch seems right.}}
I tested this on Ubuntu 18.04.1 LTS (Qt 5.9.5) and Gentoo (Qt 5.9.6).
Thanks!