Diffstat (limited to 'libopie2/opiepim/core/oconversion.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/oconversion.cpp | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/libopie2/opiepim/core/oconversion.cpp b/libopie2/opiepim/core/oconversion.cpp index 0d15414..b7eebef 100644 --- a/libopie2/opiepim/core/oconversion.cpp +++ b/libopie2/opiepim/core/oconversion.cpp | |||
@@ -1,41 +1,59 @@ | |||
1 | /********************************************************************** | 1 | /* |
2 | ** Copyright (C) 2003 by Stefan Eilers (eilers.stefan@epost.de) | 2 | This file is part of the Opie Project |
3 | ** | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | ** This file may be distributed and/or modified under the terms of the | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | ** GNU Lesser General Public License version 2 as published by the Free Software | 5 | .=l. |
6 | ** Foundation and appearing in the file LICENSE.GPL included in the | 6 | .>+-= |
7 | ** packaging of this file. | 7 | _;:, .> :=|. This program is free software; you can |
8 | ** | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | ** | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | **********************************************************************/ | 12 | ._= =} : or (at your option) any later version. |
13 | 13 | .%`+i> _;_. | |
14 | #include "oconversion.h" | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | |||
30 | #include <opie2/oconversion.h> | ||
15 | #include <qpe/timeconversion.h> | 31 | #include <qpe/timeconversion.h> |
16 | 32 | ||
17 | 33 | ||
34 | namespace Opie { | ||
35 | |||
18 | QString OConversion::dateToString( const QDate &d ) | 36 | QString OConversion::dateToString( const QDate &d ) |
19 | { | 37 | { |
20 | if ( d.isNull() || !d.isValid() ) | 38 | if ( d.isNull() || !d.isValid() ) |
21 | return QString::null; | 39 | return QString::null; |
22 | 40 | ||
23 | // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 | 41 | // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 |
24 | QString year = QString::number( d.year() ); | 42 | QString year = QString::number( d.year() ); |
25 | QString month = QString::number( d.month() ); | 43 | QString month = QString::number( d.month() ); |
26 | month = month.rightJustify( 2, '0' ); | 44 | month = month.rightJustify( 2, '0' ); |
27 | QString day = QString::number( d.day() ); | 45 | QString day = QString::number( d.day() ); |
28 | day = day.rightJustify( 2, '0' ); | 46 | day = day.rightJustify( 2, '0' ); |
29 | 47 | ||
30 | QString str = year + month + day; | 48 | QString str = year + month + day; |
31 | //qDebug( "\tPimContact dateToStr = %s", str.latin1() ); | 49 | //qDebug( "\tPimContact dateToStr = %s", str.latin1() ); |
32 | 50 | ||
33 | return str; | 51 | return str; |
34 | } | 52 | } |
35 | 53 | ||
36 | QDate OConversion::dateFromString( const QString& s ) | 54 | QDate OConversion::dateFromString( const QString& s ) |
37 | { | 55 | { |
38 | QDate date; | 56 | QDate date; |
39 | 57 | ||
40 | if ( s.isEmpty() ) | 58 | if ( s.isEmpty() ) |
41 | return date; | 59 | return date; |
@@ -90,24 +108,25 @@ QString OConversion::dateTimeToString( const QDateTime& dt ) { | |||
90 | hour = hour. rightJustify( 2, '0' ); | 108 | hour = hour. rightJustify( 2, '0' ); |
91 | min = min. rightJustify( 2, '0' ); | 109 | min = min. rightJustify( 2, '0' ); |
92 | sec = sec. rightJustify( 2, '0' ); | 110 | sec = sec. rightJustify( 2, '0' ); |
93 | 111 | ||
94 | QString str = day + month + year + hour + min + sec; | 112 | QString str = day + month + year + hour + min + sec; |
95 | 113 | ||
96 | return str; | 114 | return str; |
97 | } | 115 | } |
98 | QDateTime OConversion::dateTimeFromString( const QString& str) { | 116 | QDateTime OConversion::dateTimeFromString( const QString& str) { |
99 | 117 | ||
100 | if ( str.isEmpty() ) return QDateTime(); | 118 | if ( str.isEmpty() ) return QDateTime(); |
101 | int day = str.mid(0, 2).toInt(); | 119 | int day = str.mid(0, 2).toInt(); |
102 | int month = str.mid(2, 2).toInt(); | 120 | int month = str.mid(2, 2).toInt(); |
103 | int year = str.mid(4, 4).toInt(); | 121 | int year = str.mid(4, 4).toInt(); |
104 | int hour = str.mid(8, 2).toInt(); | 122 | int hour = str.mid(8, 2).toInt(); |
105 | int min = str.mid(10, 2).toInt(); | 123 | int min = str.mid(10, 2).toInt(); |
106 | int sec = str.mid(12, 2).toInt(); | 124 | int sec = str.mid(12, 2).toInt(); |
107 | 125 | ||
108 | QDate date( year, month, day ); | 126 | QDate date( year, month, day ); |
109 | QTime time( hour, min, sec ); | 127 | QTime time( hour, min, sec ); |
110 | QDateTime dt( date, time ); | 128 | QDateTime dt( date, time ); |
111 | return dt; | 129 | return dt; |
112 | } | 130 | } |
113 | 131 | ||
132 | } \ No newline at end of file | ||