Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
Some future release
-
None
Description
QDateTime::toString( Qt::ISODate lacks prefixed 0's on years below 1000. The iso8601 standard dictates that this should be the case.
Additionally: If the date is in UTC, A Z should be postixed, otherwise an offset for the timezone should be postfixed.
Additionally: If the date is before 1/1/1 00:00:00 UTC, the method should throw instead of returning an empty string, IMO.
Test example for first issue:
void test_early_date() { QDateTime d_datetime_def ( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ); std::cout << d_datetime_def.toString().toLocal8Bit().constData() << std::endl; std::cout << d_datetime_def.toString( Qt::ISODate ).toLocal8Bit().constData() << std::endl; std::cout << d_datetime_def.toUTC().toString().toLocal8Bit().constData() << std::endl; std::cout << d_datetime_def.toUTC().toString( Qt::ISODate ).toLocal8Bit().constData() << std::endl; d_datetime_def = QDateTime( QDate( 999, 6, 7 ), QTime( 12, 13, 14 ) ); std::cout << d_datetime_def.toString().toLocal8Bit().constData() << std::endl; std::cout << d_datetime_def.toString( Qt::ISODate ).toLocal8Bit().constData() << std::endl; std::cout << d_datetime_def.toUTC().toString().toLocal8Bit().constData() << std::endl; std::cout << d_datetime_def.toUTC().toString( Qt::ISODate ).toLocal8Bit().constData() << std::endl; }
Outputs (when running in a timezone of +01:00):
Sat Jan 1 00:00:00 1 1-01-01T00:00:00 Fri Dec 31 23:00:00 -1 (NOTHING) Wed Jun 7 12:13:14 999 999-06-07T12:13:14 Wed Jun 7 11:13:14 999 999-06-07T11:13:14
Expected
Sat Jan 1 00:00:00 1 0001-01-01T00:00:00 Fri Dec 31 23:00:00 -1 "*ERROR*" Wed Jun 7 12:13:14 999 0999-06-07T12:13:14 Wed Jun 7 11:13:14 999 0999-06-07T11:13:14
Preferred
Sat Jan 1 00:00:00 1 0001-01-01T00:00:00+01:00 Fri Dec 31 23:00:00 -1 "*ERROR*" Wed Jun 7 12:13:14 999 0999-06-07T12:13:14+01:00 Wed Jun 7 11:13:14 999 0999-06-07T11:13:14Z