From c5f65d859720c9345f995136301f6809bbb82867 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 23 Feb 2012 11:58:23 +1000 Subject: [PATCH] QML locale.firstDayOfWeek returns 7 for Sunday To match JS Date object, Sunday should be 0. Change-Id: I662c0b1fcbf921fa1c4bb58f900366dd088b343b Reviewed-by: Glenn Watson --- src/declarative/qml/qdeclarativelocale.cpp | 5 ++- .../qdeclarativelocale/tst_qdeclarativelocale.cpp | 38 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qdeclarativelocale.cpp b/src/declarative/qml/qdeclarativelocale.cpp index 39d0f6c..103378a 100644 --- a/src/declarative/qml/qdeclarativelocale.cpp +++ b/src/declarative/qml/qdeclarativelocale.cpp @@ -524,7 +524,10 @@ v8::Handle QDeclarativeNumberExtension::fromLocaleString(const v8::Ar static v8::Handle locale_get_firstDayOfWeek(v8::Local, const v8::AccessorInfo &info) { GET_LOCALE_DATA_RESOURCE(info.This()); - return v8::Integer::New(r->locale.firstDayOfWeek()); + int fdow = int(r->locale.firstDayOfWeek()); + if (fdow == 7) + fdow = 0; // Qt::Sunday = 7, but Sunday is 0 in JS Date + return v8::Integer::New(fdow); } static v8::Handle locale_get_measurementSystem(v8::Local, const v8::AccessorInfo &info) diff --git a/tests/auto/declarative/qdeclarativelocale/tst_qdeclarativelocale.cpp b/tests/auto/declarative/qdeclarativelocale/tst_qdeclarativelocale.cpp index bf5c8c7..7d86ad9 100644 --- a/tests/auto/declarative/qdeclarativelocale/tst_qdeclarativelocale.cpp +++ b/tests/auto/declarative/qdeclarativelocale/tst_qdeclarativelocale.cpp @@ -68,6 +68,8 @@ private slots: void dayName(); void standaloneDayName_data(); void standaloneDayName(); + void firstDayOfWeek_data(); + void firstDayOfWeek(); void weekDays_data(); void weekDays(); void uiLanguages_data(); @@ -154,7 +156,6 @@ void tst_qdeclarativelocale::addPropertyData(const QString &l) LOCALE_PROP(QString,negativeSign), LOCALE_PROP(QString,positiveSign), LOCALE_PROP(QString,exponential), - LOCALE_PROP(int,firstDayOfWeek), LOCALE_PROP(int,measurementSystem), LOCALE_PROP(int,textDirection), { 0, QVariant() } @@ -426,6 +427,41 @@ void tst_qdeclarativelocale::standaloneDayName() delete obj; } +void tst_qdeclarativelocale::firstDayOfWeek_data() +{ + QTest::addColumn("locale"); + + QTest::newRow("en_US") << "en_US"; + QTest::newRow("de_DE") << "de_DE"; + QTest::newRow("ar_SA") << "ar_SA"; + QTest::newRow("hi_IN") << "hi_IN"; + QTest::newRow("zh_CN") << "zh_CN"; + QTest::newRow("th_TH") << "th_TH"; +} + +void tst_qdeclarativelocale::firstDayOfWeek() +{ + QFETCH(QString, locale); + + QDeclarativeComponent c(&engine, testFileUrl("properties.qml")); + + QObject *obj = c.create(); + QVERIFY(obj); + + QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection, + Q_ARG(QVariant, QVariant(locale))); + + QVariant val = obj->property("firstDayOfWeek"); + QVERIFY(val.type() == QVariant::Int); + + int day = int(QLocale(locale).firstDayOfWeek()); + if (day == 7) // JS Date days in range 0(Sunday) to 6(Saturday) + day = 0; + QCOMPARE(day, val.toInt()); + + delete obj; +} + void tst_qdeclarativelocale::weekDays_data() { QTest::addColumn("locale"); -- 2.7.4