Reviewing merge request #455: QLocale::toDateTime cannot convert value correctly

the following code shows the issue:
//------------------------------------------------------------------------------------------------
QLocale locale = QLocale(QLocale::English);
//QString dateTimeStr = QString("Monday, January 5, 2009 11:48:32 AM"); // with no blank space char after "AM", this date time str cannot be parsed correctly
QString dateTimeStr = QString("Monday, January 5, 2009 11:48:32 AM ");

//QDateTime value = locale.toDateTime(dateTimeStr , locale.dateTimeFormat(QLocale::LongFormat)); // this will success
QDateTime value = locale.toDateTime(dateTimeStr , QLocale::LongFormat); // cannot return right QDateTime value
//------------------------------------------------------------------------------------------------
souce code of "toDateTime"
QDateTime QLocale::toDateTime(const QString &string, FormatType format) const

{ return toDateTime(string, dateFormat(format)); // "dateFormat" should be replaced by "dateTimeFormat" }

Commits that would be merged:

Version 5
  • Version 1
  • Version 2
  • Version 3
  • Version 3
  • Version 4
  • Version 4
  • Version 5
  • Version 5
  • cd4cab0
  • 1b02c71
  • fix QTBUG-7898

  • e5a0ef6
  • add test case for QTBUG-7898 that QLocale::toDateTime(QString, FormatType) cannot convert value correctly

  • 05f97da
  • remove debug info

  • c2652a8
  • add test for toDateTime() using QLocale::LongFormat

Showing cd4cab0-1b02c71

Comments

→ State changed from New to Reviewing

The patch looks good but could you add a unit test for it?

You just need add to add the two strings to tst_QLocale::toDateTime_data().

→ State changed from Reviewing to New

Looks fine. I agree with Benjamin – please add a test for it.

However I wonder how useful that QLocale::toDateTime() function is – the date/time format might change over time in newer versions of Qt when we upgrade to a newer version of Qt, so in practice you cannot rely on that conversion.

@Denis
You can probably rely on QLocale::toDateTime() and QLocale::dateTimeFormat() to be consistent. I guess this is useful for date editing widgets.

→ State changed from New to Revise and resubmit

I change the status to “revise and resubmit”. You just need to add a test to be integrated.

sure, I have added the test case for this issue

+ void tst_QLocale::QTBUG_7898()

Do you really need a new function for this test?

tst_qlocale() already test this in tst_QLocale::formatDateTime().

I think adding two lines to tst_QLocale::formatDateTime_data() should work(?).

Don’t forget to change the status back to new when you are ready for a second review.

→ State changed from Revise and resubmit to New

ok, the test code has been moved to “toDateTime”, the fail is caused by method: “QDateTime toDateTime ( const QString & string, FormatType format = LongFormat ) const”.

Also, it seems that “QLocale l("C”)“ is different from "QLocale l("en_US”)“ as if "C” is used as locale name there will be no fail. Or I might misunderstand the QLocale class, I will check it again. Thanks.

→ State changed from New to Merged

Thanks for the patch.

Merged as df09fee0363eda36d827de02a4c7e899a536ed06 to master.

Add a new comment:

Login or create an account to post a comment

How to apply this merge request to your repository