summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2013-07-17 11:38:00 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-03 14:31:06 +0200
commit5ec1c7727b887500f4c93875804f982355c230da (patch)
treec751cdeca66d8f5ae52225dec299d102b5019941 /tests/auto
parent89ee4a50b0c6d063a9abd4d3bb71cbb6887d298b (diff)
QDateTime - Add api for Time Zone Abbreviation
Add a new method to return the time zone abbreviation for the current time spec. For LocalTime this is the abbreviation returned by mktime. This new method will later be used in changes to the date formatter and QTimeZone. Note this change does not implement WinCE support. [ChangeLog][QtCore][QDateTime] Add method timeZoneAbbreviation() to return effective time zone abbreviation. Change-Id: I265a5e96c72eb7236974f80f053f1fb341e3c816 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index 5576d3d8a4..917e931988 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -133,6 +133,8 @@ private slots:
void setOffsetFromUtc();
void toOffsetFromUtc();
+ void timeZoneAbbreviation();
+
void getDate();
void fewDigitsInYear() const;
@@ -592,7 +594,7 @@ void tst_QDateTime::fromMSecsSinceEpoch()
QCOMPARE(dtUtc.time(), utc.time());
QCOMPARE(dtOffset, utc);
- QCOMPARE(dtOffset.utcOffset(), 60*60);
+ QCOMPARE(dtOffset.offsetFromUtc(), 60*60);
QCOMPARE(dtOffset.time(), utc.time().addMSecs(60*60*1000));
if (europeanTimeZone) {
@@ -2221,6 +2223,35 @@ void tst_QDateTime::toOffsetFromUtc()
QCOMPARE(dt2.time(), QTime(0, 0, 0));
}
+void tst_QDateTime::timeZoneAbbreviation()
+{
+ QDateTime dt1(QDate(2013, 1, 1), QTime(1, 0, 0), Qt::OffsetFromUTC, 60 * 60);
+ QCOMPARE(dt1.timeZoneAbbreviation(), QString("UTC+01:00"));
+ QDateTime dt2(QDate(2013, 1, 1), QTime(1, 0, 0), Qt::OffsetFromUTC, -60 * 60);
+ QCOMPARE(dt2.timeZoneAbbreviation(), QString("UTC-01:00"));
+
+ QDateTime dt3(QDate(2013, 1, 1), QTime(0, 0, 0), Qt::UTC);
+ QCOMPARE(dt3.timeZoneAbbreviation(), QString("UTC"));
+
+ // LocalTime should vary
+ if (europeanTimeZone) {
+ // Time definitely in Standard Time
+ QDateTime dt4(QDate(2013, 1, 1), QTime(0, 0, 0), Qt::LocalTime);
+#ifdef Q_OS_WIN
+ QEXPECT_FAIL("", "Windows only returns long name (QTBUG-32759)", Continue);
+#endif // Q_OS_WIN
+ QCOMPARE(dt4.timeZoneAbbreviation(), QString("CET"));
+ // Time definitely in Daylight Time
+ QDateTime dt5(QDate(2013, 6, 1), QTime(0, 0, 0), Qt::LocalTime);
+#ifdef Q_OS_WIN
+ QEXPECT_FAIL("", "Windows only returns long name (QTBUG-32759)", Continue);
+#endif // Q_OS_WIN
+ QCOMPARE(dt5.timeZoneAbbreviation(), QString("CEST"));
+ } else {
+ QSKIP("You must test using Central European (CET/CEST) time zone, e.g. TZ=Europe/Oslo");
+ }
+}
+
void tst_QDateTime::getDate()
{
{