[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-pim
Subject: [Kde-pim] [patch] vcard parser bugfix
From: Martin Koller <m.koller () surfeu ! at>
Date: 2008-12-27 22:47:37
Message-ID: 200812272347.41383.m.koller () surfeu ! at
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
Hi all,
working on the kdepim-sync opensync plugin, I found that the vcard
parsing in KDE is still broken w.r.t. time parsing of the ISO-8601
spec. ( http://en.wikipedia.org/wiki/ISO_8601#Times ) as it does not
respect the possibility of the basic format (without the ":" delimiter)
and the possibility to only have the minutes and seconds optional.
The attached patch tries to fix that, but I could not test it up till
now as I first wanted to make a standard test for it, but I stumble
over the tests as they are implemented now.
Can someone tell me how the current tests located in
kdepimlibs/kabc/vcardparser/tests can be run ?
Still, I already attach the patch here.
Another question I have is regarding KDE4 and PIM itself:
I'm still running KDE3 and the opensync-plugin I fixed now is still
using all KDE3 libs (kabc, libkcal).
Is this supposed to stay in KDE4(.2) this way, or will the libs go away
in favor of akonadi ?
So does it make any sense to make the opensync kdepim plugin also run
for KDE4 with the current implementation/libs ?
--
Best regards/Schöne Grüße
Martin () ascii ribbon campaign - against html mail
/\ - against microsoft attachments
["parseDT.patch" (text/x-diff)]
Index: vcardtool.cpp
===================================================================
--- vcardtool.cpp (Revision 901020)
+++ vcardtool.cpp (Arbeitskopie)
@@ -638,27 +638,47 @@
QDateTime VCardTool::parseDateTime( const QString &str ) const
{
- QDateTime dateTime;
+ QDate date;
+ QTime time;
if ( str.indexOf( '-' ) == -1 ) { // is base format (yyyymmdd)
- dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
- str.mid( 6, 2 ).toInt() ) );
+ date = QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
+ str.mid( 6, 2 ).toInt() );
+ } else { // is extended format yyyy-mm-dd
+ date = QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
+ str.mid( 8, 2 ).toInt() );
+ }
- if ( str.indexOf( 'T' ) ) { // has time information yyyymmddThh:mm:ss
- dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
- str.mid( 17, 2 ).toInt() ) );
+ // does it also contain a time ? (Note: mm, ss are optional according ISO-8601)
+ int timeStart = str.indexOf( 'T' );
+ if ( timeStart >= 0 ) {
+ int hour = 0, minute = 0, second = 0;
+
+ hour = str.mid( timeStart + 1, 2 ).toInt(); // hour must always be given
+
+ if ( str.indexOf( ':', timeStart + 1 ) > 0 ) { // extended format (hh:mm:ss)
+ if ( str.length() >= (timeStart + 5) ) {
+ minute = str.mid( timeStart + 4, 2 ).toInt();
+ if ( str.length() >= (timeStart + 8) ) {
+ second = str.mid( timeStart + 7, 2 ).toInt();
+ }
+ }
}
- } else { // is extended format yyyy-mm-dd
- dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
- str.mid( 8, 2 ).toInt() ) );
+ else { // basic format (hhmmss)
+ if ( str.length() >= (timeStart + 4) ) {
+ minute = str.mid( timeStart + 3, 2 ).toInt();
+ if ( str.length() >= (timeStart + 6) ) {
+ second = str.mid( timeStart + 5, 2 ).toInt();
+ }
+ }
+ }
- if ( str.indexOf( 'T' ) ) { // has time information yyyy-mm-ddThh:mm:ss
- dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
- str.mid( 17, 2 ).toInt() ) );
- }
+ time = QTime( hour, minute, second );
}
- return dateTime;
+ Qt::TimeSpec spec = (str.right( 1 ) == "Z") ? Qt::UTC : Qt::LocalTime;
+
+ return QDateTime(date, time, spec);
}
QString VCardTool::createDateTime( const QDateTime &dateTime ) const
@@ -670,9 +690,12 @@
dateTime.date().day() );
if ( dateTime.time().isValid() ) {
QString tmp;
- tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(),
+ tmp.sprintf( "T%02d:%02d:%02d", dateTime.time().hour(), dateTime.time().minute(),
dateTime.time().second() );
str += tmp;
+
+ if ( dateTime.timeSpec() == Qt::UTC )
+ str += 'Z';
}
}
["signature.asc" (application/pgp-signature)]
_______________________________________________
KDE PIM mailing list kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic