author | zecke <zecke> | 2003-05-12 13:09:39 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-05-12 13:09:39 (UTC) |
commit | 64f9f964ef690806378d639118f79539a8934d40 (patch) (unidiff) | |
tree | d49f33713aaa4078a9d51ab6f099671c72226eb5 /libopie | |
parent | 41ce7d75884224eb6fff131cc950744cb5adc0e2 (diff) | |
download | opie-64f9f964ef690806378d639118f79539a8934d40.zip opie-64f9f964ef690806378d639118f79539a8934d40.tar.gz opie-64f9f964ef690806378d639118f79539a8934d40.tar.bz2 |
dateTimeFromString
and toString added
-rw-r--r-- | libopie/pim/oconversion.cpp | 41 | ||||
-rw-r--r-- | libopie/pim/oconversion.h | 9 |
2 files changed, 47 insertions, 3 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 | |||
@@ -53,3 +53,4 @@ QDate OConversion::dateFromString( const QString& s ) | |||
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 ) { |
@@ -70,3 +71,3 @@ QDate OConversion::dateFromString( const QString& s ) | |||
70 | qWarning( "PimContact date is not valid"); | 71 | qWarning( "PimContact date is not valid"); |
71 | return QDate(); | 72 | return date; |
72 | } | 73 | } |
@@ -75,2 +76,38 @@ QDate OConversion::dateFromString( const QString& s ) | |||
75 | } | 76 | } |
77 | QString 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 | } | ||
98 | QDateTime 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 | |||
@@ -25,3 +25,3 @@ | |||
25 | 25 | ||
26 | 26 | /* FIXME namespace? -zecke */ | |
27 | class OConversion | 27 | class OConversion |
@@ -32,2 +32,9 @@ public: | |||
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 | }; |