summaryrefslogtreecommitdiff
path: root/libopie/pim
authorzecke <zecke>2003-05-12 13:09:39 (UTC)
committer zecke <zecke>2003-05-12 13:09:39 (UTC)
commit64f9f964ef690806378d639118f79539a8934d40 (patch) (unidiff)
treed49f33713aaa4078a9d51ab6f099671c72226eb5 /libopie/pim
parent41ce7d75884224eb6fff131cc950744cb5adc0e2 (diff)
downloadopie-64f9f964ef690806378d639118f79539a8934d40.zip
opie-64f9f964ef690806378d639118f79539a8934d40.tar.gz
opie-64f9f964ef690806378d639118f79539a8934d40.tar.bz2
dateTimeFromString
and toString added
Diffstat (limited to 'libopie/pim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/oconversion.cpp43
-rw-r--r--libopie/pim/oconversion.h9
2 files changed, 48 insertions, 4 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
@@ -39,9 +39,9 @@ QDate OConversion::dateFromString( const QString& s )
39 39
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() )
47 return date; 47 return date;
@@ -50,9 +50,10 @@ QDate OConversion::dateFromString( const QString& s )
50 int year = s.mid(0, 4).toInt(); 50 int year = s.mid(0, 4).toInt();
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;
58 } 59 }
@@ -67,10 +68,46 @@ QDate OConversion::dateFromString( const QString& s )
67 68
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
@@ -22,15 +22,22 @@
22/* #include <time.h> */ 22/* #include <time.h> */
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__
36 43