Commit ee2705d6 authored by Tobias Koenig's avatar Tobias Koenig
Browse files

Parse a complete QDateTime object as we export time

information as well.

BUG: 207078

svn path=/trunk/KDE/kdepim/kaddressbook/; revision=1023859
parent afe9907f
......@@ -329,14 +329,18 @@ void CSVImportDialog::initGUI()
layout->addWidget( label, 2, 2 );
mDatePatternEdit = new KLineEdit( page );
mDatePatternEdit->setText( "Y-M-D" ); // ISO 8601 format as default
mDatePatternEdit->setText( "Y-M-DTH:I:S" ); // ISO 8601 date time format as default
mDatePatternEdit->setToolTip( i18nc( "@info:tooltip",
"<para><list><item>y: year with 2 digits</item>"
"<item>Y: year with 4 digits</item>"
"<item>m: month with 1 or 2 digits</item>"
"<item>M: month with 2 digits</item>"
"<item>d: day with 1 or 2 digits</item>"
"<item>D: day with 2 digits</item></list></para>" ) );
"<item>D: day with 2 digits</item>"
"<item>H: hours with 2 digits</item>"
"<item>I: minutes with 2 digits</item>"
"<item>S: seconds with 2 digits</item>"
"</list></para>" ) );
layout->addWidget( mDatePatternEdit, 2, 3 );
// text codec
......
......@@ -28,10 +28,10 @@ DateParser::~DateParser()
{
}
QDate DateParser::parse( const QString &dateStr ) const
QDateTime DateParser::parse( const QString &dateStr ) const
{
int year, month, day;
year = month = day = 0;
int year, month, day, hour, minute, second;
year = month = day = hour = minute = second = 0;
int currPos = 0;
for ( int i = 0; i < mPattern.length(); ++i ) {
......@@ -40,13 +40,13 @@ QDate DateParser::parse( const QString &dateStr ) const
year = 1900 + dateStr.mid( currPos, 2 ).toInt();
currPos += 2;
} else
return QDate();
return QDateTime();
} else if ( mPattern[ i ] == 'Y' ) { // YYYY
if ( currPos + 3 < dateStr.length() ) {
year = dateStr.mid( currPos, 4 ).toInt();
currPos += 4;
} else
return QDate();
return QDateTime();
} else if ( mPattern[ i ] == 'm' ) { // M or MM
if ( currPos + 1 < dateStr.length() ) {
if ( dateStr[ currPos ].isDigit() ) {
......@@ -65,13 +65,13 @@ QDate DateParser::parse( const QString &dateStr ) const
}
}
return QDate();
return QDateTime();
} else if ( mPattern[ i ] == 'M' ) { // 0M or MM
if ( currPos + 1 < dateStr.length() ) {
month = dateStr.mid( currPos, 2 ).toInt();
currPos += 2;
} else
return QDate();
return QDateTime();
} else if ( mPattern[ i ] == 'd' ) { // D or DD
if ( currPos + 1 < dateStr.length() ) {
if ( dateStr[ currPos ].isDigit() ) {
......@@ -90,17 +90,35 @@ QDate DateParser::parse( const QString &dateStr ) const
}
}
return QDate();
return QDateTime();
} else if ( mPattern[ i ] == 'D' ) { // 0D or DD
if ( currPos + 1 < dateStr.length() ) {
day = dateStr.mid( currPos, 2 ).toInt();
currPos += 2;
} else
return QDate();
return QDateTime();
} else if ( mPattern[ i ] == 'H' ) { // 0H or HH
if ( currPos + 1 < dateStr.length() ) {
hour = dateStr.mid( currPos, 2 ).toInt();
currPos += 2;
} else
return QDateTime();
} else if ( mPattern[ i ] == 'I' ) { // 0I or II
if ( currPos + 1 < dateStr.length() ) {
minute = dateStr.mid( currPos, 2 ).toInt();
currPos += 2;
} else
return QDateTime();
} else if ( mPattern[ i ] == 'S' ) { // 0S or SS
if ( currPos + 1 < dateStr.length() ) {
second = dateStr.mid( currPos, 2 ).toInt();
currPos += 2;
} else
return QDateTime();
} else {
currPos++;
}
}
return QDate( year, month, day );
return QDateTime( QDate( year, month, day ), QTime( hour, minute, second ) );
}
......@@ -20,19 +20,23 @@
#ifndef DATEPARSER_H
#define DATEPARSER_H
#include <QtCore/QDate>
#include <QtCore/QDateTime>
#include <QtCore/QString>
/**
This class parses the date out of a given string with the
This class parses the datetime out of a given string with the
help of a pattern.
The pattern can contains the following key characters:
The pattern can contain the following place holders:
y = year (e.g. 82)
Y = year (e.g. 1982)
m = month (e.g. 7, 07 or 12)
M = month (e.g. 07 or 12)
d = day (e.g. 3, 03 or 17)
D = day (e.g. 03 or 17 )
D = day (e.g. 03 or 17)
H = hour (e.g. 12)
I = minute (e.g. 56)
S = second (e.g. 30)
*/
class DateParser
{
......@@ -40,7 +44,7 @@ class DateParser
DateParser( const QString &pattern );
~DateParser();
QDate parse( const QString &dateStr ) const;
QDateTime parse( const QString &dateStr ) const;
private:
QString mPattern;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment