if (localDate.getTimezoneOffset() != -600) return
- if (localDate.toLocaleString() != "Friday, June 1, 2012 2:15:30 AM AEST") return
+ if (localDate.toLocaleString() != getLocalizedForm('2012-06-01T02:15:30+10:00')) return
if (localDate.toISOString() != "2012-05-31T16:15:30.000Z") return
if (utcDate.toISOString() != "2012-06-01T02:15:30.000Z") return
- if (utcDate.toLocaleString() != "Friday, June 1, 2012 12:15:30 PM AEST") return
+ if (utcDate.toLocaleString() != getLocalizedForm('2012-06-01T12:15:30+10:00')) return
success = true
}
if (localDate.getTimezoneOffset() != -330) return
- if (localDate.toLocaleString() != "Friday, June 1, 2012 2:15:30 AM IST") return
+ if (localDate.toLocaleString() != getLocalizedForm('2012-06-01T02:15:30+05:30')) return
if (localDate.toISOString() != "2012-05-31T20:45:30.000Z") return
if (utcDate.toISOString() != "2012-06-01T06:45:30.000Z") return
- if (utcDate.toLocaleString() != "Friday, June 1, 2012 12:15:30 PM IST") return
+ if (utcDate.toLocaleString() != getLocalizedForm("2012-06-01T12:15:30+05:30")) return
// Create new dates in this timezone
localDate = new Date(2012, 6-1, 1, 2, 15, 30)
utcDate = new Date(Date.UTC(2012, 6-1, 1, 2, 15, 30))
- if (localDate.toLocaleString() != "Friday, June 1, 2012 2:15:30 AM IST") return
+ if (localDate.toLocaleString() != getLocalizedForm("2012-06-01T02:15:30+05:30")) return
if (localDate.toISOString() != "2012-05-31T20:45:30.000Z") return
if (utcDate.toISOString() != "2012-06-01T02:15:30.000Z") return
- if (utcDate.toLocaleString() != "Friday, June 1, 2012 7:45:30 AM IST") return
+ if (utcDate.toLocaleString() != getLocalizedForm("2012-06-01T07:45:30+05:30")) return
success = true
}
+
+ function resetTimeZone() {
+ Date.timeZoneUpdated()
+ }
}
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlcontext.h>
#include <QtCore/QDateTime>
#include <qcolor.h>
#include "../../shared/util.h"
#endif
}
+class DateFormatter : public QObject
+{
+ Q_OBJECT
+public:
+ DateFormatter() : QObject() {}
+
+ Q_INVOKABLE QString getLocalizedForm(const QString &isoTimestamp);
+};
+
+QString DateFormatter::getLocalizedForm(const QString &isoTimestamp)
+{
+ QDateTime input = QDateTime::fromString(isoTimestamp, Qt::ISODate);
+ QLocale locale;
+ return locale.toString(input);
+}
+
void tst_qqmllocale::timeZoneUpdated()
{
-#if !defined(Q_OS_WIN32) && !defined(Q_OS_UINX)
+#if !defined(Q_OS_UNIX)
+ // Currently disabled on Windows as adjusting the timezone
+ // requires additional privileges that aren't normally
+ // enabled for a process. This can be achieved by calling
+ // AdjustTokenPrivileges() and then SetTimeZoneInformation(),
+ // which will require linking to a different library to access that API.
QSKIP("Timezone manipulation not available for this platform");
#endif
// Set the timezone to Brisbane time
setTimeZone(QByteArray("AEST-10:00"));
+ DateFormatter formatter;
+
QQmlEngine e;
+ e.rootContext()->setContextObject(&formatter);
+
QQmlComponent c(&e, testFileUrl("timeZoneUpdated.qml"));
QScopedPointer<QObject> obj(c.create());
QVERIFY(obj);
// Reset to original time
setTimeZone(original);
+ QMetaObject::invokeMethod(obj.data(), "resetTimeZone");
QCOMPARE(obj->property("success").toBool(), true);
}