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

Jon Severinsson jon at severinsson.net
Fri Oct 26 15:30:56 UTC 2012


torsdagen den 25 oktober 2012 23:15:21 skrev  David Faure:
> On Thursday 25 October 2012 22:47:00 Jon Severinsson wrote:
> > Getting a valid KDateTime with a "valid but garbage" timezone spec is
> > currently as simple as this:
> > KTzfileTimeZoneSource source("/invalid/tzinfo/dir");
> > KDateTime
> > date(QDate(2000,1,1),QTime(0,0,0),KTzfileTimeZone(&source,"Europe/London"
> > )) ; But what to do whith that?
> 
> Call toString and check what you get ;)
> Well -- that's the unittest for my patch then! Thanks for the input, this
> allowed me to finish it. Attached.
> 
> > I could fix KDateTime::Spec::setType(KTimeZone) (and thus the implicit
> > constructor) to detect "valid but garbage" as an KDateTime::Invalid time
> > zone spec and verify that the KDateTime is considered invalid.
> 
> Ah, that's another possibility, yes. That would make my patch useless then,
> but that's fine :-)
> 
> I'm no KDateTime expert, I'll let you choose the solution that makes sense
> to you.

I'm no expert either, but I have picked up a few things over the last couple 
of weeks, and IMHO such a KDateTime should be invalid, but not null, and 
toString should result in a sensible, though invalid, string.

I have therefore updated your patch (see attachment) to fix 
KDateTime::Spec::setType(KTimeZone)  as I proposed, changed the validation 
check at the top of toString() to "if (!d->dt().isValid())" and adapted your 
toString() fix to check for  "d->specType == Invalid" (as well as "offset == 
KTimeZone::InvalidOffset", just in case something has gone wrong with the time 
zone after the original check).

I also changed "+invalidtz" to "+EINVAL", as I think an error code makes more 
sence than an non-translatable error text.

Best regards
Jon Severinsson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Fix-isValid-and-toString-for-a-KDateTime-constructed.patch
Type: text/x-patch
Size: 3371 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20121026/83aa3819/attachment.patch>
-------------- 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/20121026/83aa3819/attachment.sig>


More information about the Kde-frameworks-devel mailing list