summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
Unidiff
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/oconversion.cpp43
-rw-r--r--libopie2/opiepim/core/oconversion.h9
2 files changed, 48 insertions, 4 deletions
diff --git a/libopie2/opiepim/core/oconversion.cpp b/libopie2/opiepim/core/oconversion.cpp
index c3aa89b..0d15414 100644
--- a/libopie2/opiepim/core/oconversion.cpp
+++ b/libopie2/opiepim/core/oconversion.cpp
@@ -41,5 +41,5 @@ QDate OConversion::dateFromString( const QString& s )
41 return date; 41 return date;
42 42
43 // Be backward compatible to old Opie format: 43 // Be backward compatible to old Opie format:
44 // Try to load old format. If it fails, try new ISO-Format! 44 // Try to load old format. If it fails, try new ISO-Format!
45 date = TimeConversion::fromString ( s ); 45 date = TimeConversion::fromString ( s );
@@ -52,5 +52,6 @@ QDate OConversion::dateFromString( const QString& s )
52 int day = s.mid(6,2).toInt(); 52 int day = s.mid(6,2).toInt();
53 53
54 // do some quick sanity checking 54 // do some quick sanity checking -eilers
55 // but we isValid() again? -zecke
55 if ( year < 1900 || year > 3000 ) { 56 if ( year < 1900 || year > 3000 ) {
56 qWarning( "PimContact year is not in range"); 57 qWarning( "PimContact year is not in range");
@@ -69,8 +70,44 @@ QDate OConversion::dateFromString( const QString& s )
69 if ( !date.isValid() ) { 70 if ( !date.isValid() ) {
70 qWarning( "PimContact date is not valid"); 71 qWarning( "PimContact date is not valid");
71 return QDate(); 72 return date;
72 } 73 }
73 74
74 return date; 75 return date;
75} 76}
77QString OConversion::dateTimeToString( const QDateTime& dt ) {
78 if (!dt.isValid() || dt.isNull() ) return QString::null;
79
80 QString year = QString::number( dt.date().year() );
81 QString month = QString::number( dt.date().month() );
82 QString day = QString::number( dt.date().day() );
83
84 QString hour = QString::number( dt.time().hour() );
85 QString min = QString::number( dt.time().minute() );
86 QString sec = QString::number( dt.time().second() );
87
88 month = month.rightJustify( 2, '0' );
89 day = day. rightJustify( 2, '0' );
90 hour = hour. rightJustify( 2, '0' );
91 min = min. rightJustify( 2, '0' );
92 sec = sec. rightJustify( 2, '0' );
93
94 QString str = day + month + year + hour + min + sec;
95
96 return str;
97}
98QDateTime OConversion::dateTimeFromString( const QString& str) {
99
100 if ( str.isEmpty() ) return QDateTime();
101 int day = str.mid(0, 2).toInt();
102 int month = str.mid(2, 2).toInt();
103 int year = str.mid(4, 4).toInt();
104 int hour = str.mid(8, 2).toInt();
105 int min = str.mid(10, 2).toInt();
106 int sec = str.mid(12, 2).toInt();
107
108 QDate date( year, month, day );
109 QTime time( hour, min, sec );
110 QDateTime dt( date, time );
111 return dt;
112}
76 113
diff --git a/libopie2/opiepim/core/oconversion.h b/libopie2/opiepim/core/oconversion.h
index 6540889..13367e1 100644
--- a/libopie2/opiepim/core/oconversion.h
+++ b/libopie2/opiepim/core/oconversion.h
@@ -24,5 +24,5 @@
24#include <qdatetime.h> 24#include <qdatetime.h>
25 25
26 26/* FIXME namespace? -zecke */
27class OConversion 27class OConversion
28{ 28{
@@ -31,4 +31,11 @@ public:
31 static QDate dateFromString( const QString &datestr ); 31 static QDate dateFromString( const QString &datestr );
32 32
33 /**
34 * simple function to store DateTime as string and read from string
35 * no timezone changing is done
36 * DDMMYYYYHHMMSS is the simple format
37 */
38 static QString dateTimeToString( const QDateTime& );
39 static QDateTime dateTimeFromString( const QString& );
33}; 40};
34 41