my own kdatetime patches: toString with InvalidOffset; operator==

Jon Severinsson jon at severinsson.net
Thu Oct 25 14:30:20 UTC 2012


fredagen den 19 oktober 2012 20:50:16 skrev  David Faure:
> diff --git a/kdecore/date/kdatetime.cpp b/kdecore/date/kdatetime.cpp
> index 910e1cf..74e82ca 100644
> --- a/kdecore/date/kdatetime.cpp
> +++ b/kdecore/date/kdatetime.cpp
> @@ -1773,6 +1773,8 @@ QString KDateTime::toString(TimeFormat format) const
>              offset = d->timeZoneOffset();   // calculate offset and cache
> UTC value else
>              offset = tz.isValid() ? tz.offsetAtZoneTime(d->dt()) :
> d->specUtcOffset; +        if (offset == KTimeZone::InvalidOffset)
> +            return result + QLatin1Char(tzsign) +
> QLatin1String("invalidtz"); if (offset < 0)
>          {
>              offset = -offset;
> 
> Without this fix, an invalid timezone led to a string representation like
> this: KDateTime(2012-10-19T00:00:00--596523:-14)
> Nasty overflow in there, leading to '-' as a char followed by a negative
> number ;) (This is due to InvalidOffset being equal to 0x80000000)
> Now it prints:
>   KDateTime(2012-10-19T00:00:00+invalidtz)
> which is at least readable. It's invalid, of course, but it's readable :)
> Should it say something else?
> 
> 
> For the curious: this is how I triggered this issue:
> running kdatetimeedittest in an isolated kdelibs-frameworks-with-qt4
> environment.
> 
> [ ... ]

I triggered this in Qt5 too, and I figured out the underlying reason for it to 
happen. If, when KSystemTimeZonesPrivate::setLocalZone() tries to figure out 
what time zone to use for KSystemTimeZones::local(), the kconfig 
"ktimezonedrc"/ "TimeZones"/"LocalZone" time zone does not exist in the kconfig 
"ktimezonedrc"/"TimeZones"/"ZoneinfoDir" directory, it will create a "valid" 
KTzTimeZone with garbage data.

This happens because KDateTimeTest::cleanupTestCase() successfully removes the 
temporary zoneinfo dir it creates, but used the wrong path when trying to 
remove the ktimezonedrc kconfig file.

Patches for both KDateTimeTest::cleanupTestCase() and 
KSystemTimeZonesPrivate::setLocalZone() will be uploaded to review board 
shortly.

Regards
Jon Severinsson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20121025/007f2b7e/attachment.sig>


More information about the Kde-frameworks-devel mailing list