Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KDDateTime does not handle time zone strings correctly #299

Open
jtjbrady opened this issue Nov 28, 2024 · 0 comments
Open

KDDateTime does not handle time zone strings correctly #299

jtjbrady opened this issue Nov 28, 2024 · 0 comments

Comments

@jtjbrady
Copy link

jtjbrady commented Nov 28, 2024

I do not believe KDDateTime handles time zones strings for fractional time zones correctly.

The code in question is:

        setTimeSpec(Qt::OffsetFromUTC);
        const int pos = timeZone.indexOf(QLatin1Char(':'));
        if (pos > 0) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
            const int hours = timeZone.leftRef(pos).toInt();
            const int minutes = timeZone.midRef(pos + 1).toInt();
#else
            const QStringView timeZoneView(timeZone);
            const int hours = timeZoneView.first(pos).toInt();
            const int minutes = timeZoneView.sliced(pos + 1).toInt();
#endif
            const int offset = hours * 3600 + minutes * 60;
            setOffsetFromUtc(offset);
        }

Fractional time zones which is what this issue is about. There are only a few in use and even fewer which are a negative UTC offset. Looking at the example of Newfoundland, Canada which has an offset of -3:30/-2:30 depending on daylight savings and looking specifically at -3:30:

The hours extracted by the above code would be -3.
The minutes extracted by the above code would be + 30.

The line:
const int offset = hours * 3600 + minutes * 60;
Would give an offset of -3 * 3600 or - 10800, plus 1800, giving an offset of -9000 seconds, or 2 1/2 hours instead of 3 1/2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant