summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/oconversion.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/oconversion.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/oconversion.cpp39
1 files changed, 25 insertions, 14 deletions
diff --git a/libopie2/opiepim/core/oconversion.cpp b/libopie2/opiepim/core/oconversion.cpp
index b7eebef..160c2c6 100644
--- a/libopie2/opiepim/core/oconversion.cpp
+++ b/libopie2/opiepim/core/oconversion.cpp
@@ -1,6 +1,5 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 3 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 4 .=l.
6 .>+-= 5 .>+-=
@@ -27,11 +26,12 @@
27 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
28*/ 27*/
29 28
29/* OPIE */
30#include <opie2/oconversion.h> 30#include <opie2/oconversion.h>
31#include <qpe/timeconversion.h> 31#include <qpe/timeconversion.h>
32 32
33 33namespace Opie
34namespace Opie { 34{
35 35
36QString OConversion::dateToString( const QDate &d ) 36QString OConversion::dateToString( const QDate &d )
37{ 37{
@@ -51,6 +51,7 @@ QString OConversion::dateToString( const QDate &d )
51 return str; 51 return str;
52} 52}
53 53
54
54QDate OConversion::dateFromString( const QString& s ) 55QDate OConversion::dateFromString( const QString& s )
55{ 56{
56 QDate date; 57 QDate date;
@@ -71,29 +72,37 @@ QDate OConversion::dateFromString( const QString& s )
71 72
72 // do some quick sanity checking -eilers 73 // do some quick sanity checking -eilers
73 // but we isValid() again? -zecke 74 // but we isValid() again? -zecke
74 if ( year < 1900 || year > 3000 ) { 75 if ( year < 1900 || year > 3000 )
76 {
75 qWarning( "PimContact year is not in range"); 77 qWarning( "PimContact year is not in range");
76 return date; 78 return date;
77 } 79 }
78 if ( month < 0 || month > 12 ) { 80 if ( month < 0 || month > 12 )
81 {
79 qWarning( "PimContact month is not in range"); 82 qWarning( "PimContact month is not in range");
80 return date; 83 return date;
81 } 84 }
82 if ( day < 0 || day > 31 ) { 85 if ( day < 0 || day > 31 )
86 {
83 qWarning( "PimContact day is not in range"); 87 qWarning( "PimContact day is not in range");
84 return date; 88 return date;
85 } 89 }
86 90
87 date.setYMD( year, month, day ); 91 date.setYMD( year, month, day );
88 if ( !date.isValid() ) { 92 if ( !date.isValid() )
93 {
89 qWarning( "PimContact date is not valid"); 94 qWarning( "PimContact date is not valid");
90 return date; 95 return date;
91 } 96 }
92 97
93 return date; 98 return date;
94} 99}
95QString OConversion::dateTimeToString( const QDateTime& dt ) { 100
96 if (!dt.isValid() || dt.isNull() ) return QString::null; 101
102QString OConversion::dateTimeToString( const QDateTime& dt )
103{
104 if ( !dt.isValid() || dt.isNull() )
105 return QString::null;
97 106
98 QString year = QString::number( dt.date().year() ); 107 QString year = QString::number( dt.date().year() );
99 QString month = QString::number( dt.date().month() ); 108 QString month = QString::number( dt.date().month() );
@@ -109,13 +118,15 @@ QString OConversion::dateTimeToString( const QDateTime& dt ) {
109 min = min. rightJustify( 2, '0' ); 118 min = min. rightJustify( 2, '0' );
110 sec = sec. rightJustify( 2, '0' ); 119 sec = sec. rightJustify( 2, '0' );
111 120
112 QString str = day + month + year + hour + min + sec; 121 return day + month + year + hour + min + sec;
113
114 return str;
115} 122}
116QDateTime OConversion::dateTimeFromString( const QString& str) {
117 123
118 if ( str.isEmpty() ) return QDateTime(); 124
125QDateTime OConversion::dateTimeFromString( const QString& str )
126{
127
128 if ( str.isEmpty() )
129 return QDateTime();
119 int day = str.mid(0, 2).toInt(); 130 int day = str.mid(0, 2).toInt();
120 int month = str.mid(2, 2).toInt(); 131 int month = str.mid(2, 2).toInt();
121 int year = str.mid(4, 4).toInt(); 132 int year = str.mid(4, 4).toInt();