Skip to content

Commit 90b979b

Browse files
committed
Correct time zone offset calculation fixes #299.
1 parent c87a18a commit 90b979b

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

src/KDSoapClient/KDDateTime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void KDDateTime::setTimeZone(const QString &timeZone)
9292
const int hours = timeZoneView.first(pos).toInt();
9393
const int minutes = timeZoneView.sliced(pos + 1).toInt();
9494
#endif
95-
const int offset = hours * 3600 + minutes * 60;
95+
const int offset = hours * 3600 + (hours >= 0 ? minutes : -minutes) * 60;
9696
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
9797
setOffsetFromUtc(offset);
9898
#else

unittests/kddatetime/test_kddatetime.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "KDDateTime.h"
1212
#include "KDSoapValue.h"
1313
#include <QTest>
14+
#include <QTimeZone>
1415

1516
class KDDateTimeTest : public QObject
1617
{
@@ -35,6 +36,63 @@ private Q_SLOTS:
3536
QCOMPARE(inputDateTime.timeZone(), outputDateTime.timeZone());
3637
QCOMPARE(inputDateTime.toDateString(), outputDateTime.toDateString());
3738
}
39+
40+
void testSetTimeZone_data()
41+
{
42+
QTest::addColumn<QString>("timeZone");
43+
QTest::addColumn<QString>("expected");
44+
45+
// Example countries and their offsets.
46+
47+
QTest::newRow("empty") << "" << QDateTime({2020, 1, 1}, {0, 0}, QTimeZone::systemTimeZone()).timeZoneAbbreviation();
48+
QTest::newRow("Z") << "Z" << "UTC";
49+
QTest::newRow("US Minor outlying islands") << "-12:00" << "UTC-12:00";
50+
QTest::newRow("New Zealand (Niue)") << "-11:00" << "UTC-11:00";
51+
QTest::newRow("Hawaii") << "-10:00" << "UTC-10:00";
52+
QTest::newRow("Marquesas Islands (French Polynesia)") << "-09:30" << "UTC-09:30";
53+
QTest::newRow("Alaska") << "-09:00" << "UTC-09:00";
54+
QTest::newRow("US Pacific") << "-08:00" << "UTC-08:00";
55+
QTest::newRow("US Mountain") << "-07:00" << "UTC-07:00";
56+
QTest::newRow("US Central") << "-06:00" << "UTC-06:00";
57+
QTest::newRow("US Eastern") << "-05:00" << "UTC-05:00";
58+
QTest::newRow("US Atlantic") << "-04:00" << "UTC-04:00";
59+
QTest::newRow("Canada Newfoundland") << "-03:30" << "UTC-03:30";
60+
QTest::newRow("Argentina") << "-03:00" << "UTC-03:00";
61+
QTest::newRow("Greenland") << "-02:00" << "UTC-02:00";
62+
QTest::newRow("Cape Verde") << "-01:00" << "UTC-01:00";
63+
QTest::newRow("United Kingdom 1") << "+00:00" << "UTC";
64+
QTest::newRow("United Kingdom 2") << "-00:00" << "UTC";
65+
QTest::newRow("France (Metropolitan)") << "+01:00" << "UTC+01:00";
66+
QTest::newRow("Greece") << "+02:00" << "UTC+02:00";
67+
QTest::newRow("Turkey") << "+03:00" << "UTC+03:00";
68+
QTest::newRow("Iran") << "+03:30" << "UTC+03:30";
69+
QTest::newRow("Seychelles") << "+04:00" << "UTC+04:00";
70+
QTest::newRow("Afghanistan") << "+04:30" << "UTC+04:30";
71+
QTest::newRow("Kazakhstan") << "+05:00" << "UTC+05:00";
72+
QTest::newRow("India") << "+05:30" << "UTC+05:30";
73+
QTest::newRow("Bhutan") << "+06:00" << "UTC+06:00";
74+
QTest::newRow("Myanmar") << "+06:30" << "UTC+06:30";
75+
QTest::newRow("Cambodia") << "+07:00" << "UTC+07:00";
76+
QTest::newRow("Western Australia") << "+08:00" << "UTC+08:00";
77+
QTest::newRow("Western Australia (Eucla)") << "+08:45" << "UTC+08:45";
78+
QTest::newRow("Japan") << "+09:00" << "UTC+09:00";
79+
QTest::newRow("Australia (Adelaide)") << "+09:30" << "UTC+09:30";
80+
QTest::newRow("Australia (Sydney)") << "+10:00" << "UTC+10:00";
81+
QTest::newRow("Australia (Lord Howe Island)") << "+10:30" << "UTC+10:30";
82+
QTest::newRow("Australia (Norfolk Island)") << "+11:00" << "UTC+11:00";
83+
QTest::newRow("New Zealand") << "+12:00" << "UTC+12:00";
84+
QTest::newRow("New Zealand (Chatham Islands)") << "+12:45" << "UTC+12:45";
85+
QTest::newRow("Samoa") << "+13:00" << "UTC+13:00";
86+
QTest::newRow("Kiribati (Line Islands)") << "+14:00" << "UTC+14:00";
87+
}
88+
89+
void testSetTimeZone()
90+
{
91+
QFETCH(QString, timeZone);
92+
QFETCH(QString, expected);
93+
94+
QCOMPARE(KDDateTime::fromDateString("2020-01-01T00:00" + timeZone).timeZoneAbbreviation(), expected);
95+
}
3896
};
3997

4098
QTEST_MAIN(KDDateTimeTest)

unittests/kdwsdl2cpp_jobs/test_jobs.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,15 @@
22
**
33
** This file is part of the KD Soap project.
44
**
5-
** SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5+
** SPDX-FileCopyrightText: 2025 Jonathan Brady <jtjbrady@users.noreply.github.com>
66
**
77
** SPDX-License-Identifier: MIT
88
**
99
****************************************************************************/
1010

11-
#include "KDSoapClientInterface.h"
12-
#include "KDSoapMessage.h"
13-
#include "KDSoapPendingCallWatcher.h"
14-
#include "KDSoapValue.h"
15-
#include "httpserver_p.h"
1611
#include "wsdl_jobs.h"
17-
#include <QDebug>
18-
#include <QEventLoop>
1912
#include <QTest>
2013

21-
using namespace KDSoapUnitTestHelpers;
22-
2314
class LiteralTest : public QObject
2415
{
2516
Q_OBJECT

0 commit comments

Comments
 (0)