summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/oconversion.cpp43
-rw-r--r--libopie/pim/oconversion.h9
-rw-r--r--libopie2/opiepim/core/oconversion.cpp43
-rw-r--r--libopie2/opiepim/core/oconversion.h9
4 files changed, 96 insertions, 8 deletions
diff --git a/libopie/pim/oconversion.cpp b/libopie/pim/oconversion.cpp
index c3aa89b..0d15414 100644
--- a/libopie/pim/oconversion.cpp
+++ b/libopie/pim/oconversion.cpp
@@ -40,7 +40,7 @@ QDate OConversion::dateFromString( const QString& s )
40 if ( s.isEmpty() ) 40 if ( s.isEmpty() )
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 );
46 if ( date.isValid() ) 46 if ( date.isValid() )
@@ -51,7 +51,8 @@ QDate OConversion::dateFromString( const QString& s )
51 int month = s.mid(4,2).toInt(); 51 int month = s.mid(4,2).toInt();
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");
57 return date; 58 return date;
@@ -68,9 +69,45 @@ QDate OConversion::dateFromString( const QString& s )
68 date.setYMD( year, month, day ); 69 date.setYMD( year, month, day );
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/libopie/pim/oconversion.h b/libopie/pim/oconversion.h
index 6540889..13367e1 100644
--- a/libopie/pim/oconversion.h
+++ b/libopie/pim/oconversion.h
@@ -23,13 +23,20 @@
23/* #include <sys/types.h> */ 23/* #include <sys/types.h> */
24#include <qdatetime.h> 24#include <qdatetime.h>
25 25
26 26/* FIXME namespace? -zecke */
27class OConversion 27class OConversion
28{ 28{
29public: 29public:
30 static QString dateToString( const QDate &d ); 30 static QString dateToString( const QDate &d );
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
35#endif // __oconversion_h__ 42#endif // __oconversion_h__
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
@@ -40,7 +40,7 @@ QDate OConversion::dateFromString( const QString& s )
40 if ( s.isEmpty() ) 40 if ( s.isEmpty() )
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 );
46 if ( date.isValid() ) 46 if ( date.isValid() )
@@ -51,7 +51,8 @@ QDate OConversion::dateFromString( const QString& s )
51 int month = s.mid(4,2).toInt(); 51 int month = s.mid(4,2).toInt();
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");
57 return date; 58 return date;
@@ -68,9 +69,45 @@ QDate OConversion::dateFromString( const QString& s )
68 date.setYMD( year, month, day ); 69 date.setYMD( year, month, day );
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
@@ -23,13 +23,20 @@
23/* #include <sys/types.h> */ 23/* #include <sys/types.h> */
24#include <qdatetime.h> 24#include <qdatetime.h>
25 25
26 26/* FIXME namespace? -zecke */
27class OConversion 27class OConversion
28{ 28{
29public: 29public:
30 static QString dateToString( const QDate &d ); 30 static QString dateToString( const QDate &d );
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
35#endif // __oconversion_h__ 42#endif // __oconversion_h__