Diffstat (limited to 'libopie2/opiepim/core/opimdateconversion.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimdateconversion.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/libopie2/opiepim/core/opimdateconversion.cpp b/libopie2/opiepim/core/opimdateconversion.cpp index 8bf891b..c93e178 100644 --- a/libopie2/opiepim/core/opimdateconversion.cpp +++ b/libopie2/opiepim/core/opimdateconversion.cpp | |||
@@ -19,43 +19,45 @@ _;:, .> :=|. This program is free software; you can | |||
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | /* OPIE */ | 29 | /* OPIE */ |
30 | #include <opie2/opimdateconversion.h> | 30 | #include <opie2/opimdateconversion.h> |
31 | #include <opie2/odebug.h> | ||
32 | |||
31 | #include <qpe/timeconversion.h> | 33 | #include <qpe/timeconversion.h> |
32 | 34 | ||
33 | namespace Opie | 35 | namespace Opie |
34 | { | 36 | { |
35 | 37 | ||
36 | QString OPimDateConversion::dateToString( const QDate &d ) | 38 | QString OPimDateConversion::dateToString( const QDate &d ) |
37 | { | 39 | { |
38 | if ( d.isNull() || !d.isValid() ) | 40 | if ( d.isNull() || !d.isValid() ) |
39 | return QString::null; | 41 | return QString::null; |
40 | 42 | ||
41 | // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 | 43 | // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 |
42 | QString year = QString::number( d.year() ); | 44 | QString year = QString::number( d.year() ); |
43 | QString month = QString::number( d.month() ); | 45 | QString month = QString::number( d.month() ); |
44 | month = month.rightJustify( 2, '0' ); | 46 | month = month.rightJustify( 2, '0' ); |
45 | QString day = QString::number( d.day() ); | 47 | QString day = QString::number( d.day() ); |
46 | day = day.rightJustify( 2, '0' ); | 48 | day = day.rightJustify( 2, '0' ); |
47 | 49 | ||
48 | QString str = year + month + day; | 50 | QString str = year + month + day; |
49 | //qDebug( "\tPimContact dateToStr = %s", str.latin1() ); | 51 | //odebug << "\tPimContact dateToStr = " << str << "" << oendl; |
50 | 52 | ||
51 | return str; | 53 | return str; |
52 | } | 54 | } |
53 | 55 | ||
54 | 56 | ||
55 | QDate OPimDateConversion::dateFromString( const QString& s ) | 57 | QDate OPimDateConversion::dateFromString( const QString& s ) |
56 | { | 58 | { |
57 | QDate date; | 59 | QDate date; |
58 | 60 | ||
59 | if ( s.isEmpty() ) | 61 | if ( s.isEmpty() ) |
60 | return date; | 62 | return date; |
61 | 63 | ||
@@ -65,42 +67,42 @@ QDate OPimDateConversion::dateFromString( const QString& s ) | |||
65 | if ( date.isValid() ) | 67 | if ( date.isValid() ) |
66 | return date; | 68 | return date; |
67 | 69 | ||
68 | // Read ISO-Format (YYYYMMDD) | 70 | // Read ISO-Format (YYYYMMDD) |
69 | int year = s.mid( 0, 4 ).toInt(); | 71 | int year = s.mid( 0, 4 ).toInt(); |
70 | int month = s.mid( 4, 2 ).toInt(); | 72 | int month = s.mid( 4, 2 ).toInt(); |
71 | int day = s.mid( 6, 2 ).toInt(); | 73 | int day = s.mid( 6, 2 ).toInt(); |
72 | 74 | ||
73 | // do some quick sanity checking -eilers | 75 | // do some quick sanity checking -eilers |
74 | // but we isValid() again? -zecke | 76 | // but we isValid() again? -zecke |
75 | if ( year < 1900 || year > 3000 ) | 77 | if ( year < 1900 || year > 3000 ) |
76 | { | 78 | { |
77 | qWarning( "PimContact year is not in range" ); | 79 | owarn << "PimContact year is not in range" << oendl; |
78 | return date; | 80 | return date; |
79 | } | 81 | } |
80 | if ( month < 0 || month > 12 ) | 82 | if ( month < 0 || month > 12 ) |
81 | { | 83 | { |
82 | qWarning( "PimContact month is not in range" ); | 84 | owarn << "PimContact month is not in range" << oendl; |
83 | return date; | 85 | return date; |
84 | } | 86 | } |
85 | if ( day < 0 || day > 31 ) | 87 | if ( day < 0 || day > 31 ) |
86 | { | 88 | { |
87 | qWarning( "PimContact day is not in range" ); | 89 | owarn << "PimContact day is not in range" << oendl; |
88 | return date; | 90 | return date; |
89 | } | 91 | } |
90 | 92 | ||
91 | date.setYMD( year, month, day ); | 93 | date.setYMD( year, month, day ); |
92 | if ( !date.isValid() ) | 94 | if ( !date.isValid() ) |
93 | { | 95 | { |
94 | qWarning( "PimContact date is not valid" ); | 96 | owarn << "PimContact date is not valid" << oendl; |
95 | return date; | 97 | return date; |
96 | } | 98 | } |
97 | 99 | ||
98 | return date; | 100 | return date; |
99 | } | 101 | } |
100 | 102 | ||
101 | 103 | ||
102 | QString OPimDateConversion::dateTimeToString( const QDateTime& dt ) | 104 | QString OPimDateConversion::dateTimeToString( const QDateTime& dt ) |
103 | { | 105 | { |
104 | if ( !dt.isValid() || dt.isNull() ) | 106 | if ( !dt.isValid() || dt.isNull() ) |
105 | return QString::null; | 107 | return QString::null; |
106 | 108 | ||