-rw-r--r-- | kabc/vcard/DateValue.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/kabc/vcard/DateValue.cpp b/kabc/vcard/DateValue.cpp index c5c5c85..87c7007 100644 --- a/kabc/vcard/DateValue.cpp +++ b/kabc/vcard/DateValue.cpp | |||
@@ -1,344 +1,346 @@ | |||
1 | /* | 1 | /* |
2 | libvcard - vCard parsing library for vCard version 3.0 | 2 | libvcard - vCard parsing library for vCard version 3.0 |
3 | 3 | ||
4 | Copyright (C) 1998 Rik Hemsley rik@kde.org | 4 | Copyright (C) 1998 Rik Hemsley rik@kde.org |
5 | 5 | ||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | of this software and associated documentation files (the "Software"), to | 7 | of this software and associated documentation files (the "Software"), to |
8 | deal in the Software without restriction, including without limitation the | 8 | deal in the Software without restriction, including without limitation the |
9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
10 | sell copies of the Software, and to permit persons to whom the Software is | 10 | sell copies of the Software, and to permit persons to whom the Software is |
11 | furnished to do so, subject to the following conditions: | 11 | furnished to do so, subject to the following conditions: |
12 | 12 | ||
13 | The above copyright notice and this permission notice shall be included in | 13 | The above copyright notice and this permission notice shall be included in |
14 | all copies or substantial portions of the Software. | 14 | all copies or substantial portions of the Software. |
15 | 15 | ||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qregexp.h> | 24 | #include <qregexp.h> |
25 | //Added by qt3to4: | ||
26 | #include <Q3CString> | ||
25 | 27 | ||
26 | #include <kdebug.h> | 28 | #include <kdebug.h> |
27 | 29 | ||
28 | #include <VCardDefines.h> | 30 | #include <VCardDefines.h> |
29 | #include <VCardDateValue.h> | 31 | #include <VCardDateValue.h> |
30 | #include <VCardValue.h> | 32 | #include <VCardValue.h> |
31 | 33 | ||
32 | using namespace VCARD; | 34 | using namespace VCARD; |
33 | 35 | ||
34 | DateValue::DateValue() | 36 | DateValue::DateValue() |
35 | :Value() | 37 | :Value() |
36 | { | 38 | { |
37 | vDebug("DateValue::DateValue()"); | 39 | vDebug("DateValue::DateValue()"); |
38 | } | 40 | } |
39 | 41 | ||
40 | DateValue::DateValue( | 42 | DateValue::DateValue( |
41 | unsigned intyear, | 43 | unsigned intyear, |
42 | unsigned intmonth, | 44 | unsigned intmonth, |
43 | unsigned intday, | 45 | unsigned intday, |
44 | unsigned inthour, | 46 | unsigned inthour, |
45 | unsigned intminute, | 47 | unsigned intminute, |
46 | unsigned intsecond, | 48 | unsigned intsecond, |
47 | double secFrac, | 49 | double secFrac, |
48 | bool zonePositive, | 50 | bool zonePositive, |
49 | unsigned intzoneHour, | 51 | unsigned intzoneHour, |
50 | unsigned intzoneMinute) | 52 | unsigned intzoneMinute) |
51 | : Value (), | 53 | : Value (), |
52 | year_ (year), | 54 | year_ (year), |
53 | month_ (month), | 55 | month_ (month), |
54 | day_ (day), | 56 | day_ (day), |
55 | hour_ (hour), | 57 | hour_ (hour), |
56 | minute_ (minute), | 58 | minute_ (minute), |
57 | second_ (second), | 59 | second_ (second), |
58 | zoneHour_ (zoneHour), | 60 | zoneHour_ (zoneHour), |
59 | zoneMinute_ (zoneMinute), | 61 | zoneMinute_ (zoneMinute), |
60 | secFrac_ (secFrac), | 62 | secFrac_ (secFrac), |
61 | zonePositive_(zonePositive), | 63 | zonePositive_(zonePositive), |
62 | hasTime_(true) | 64 | hasTime_(true) |
63 | { | 65 | { |
64 | parsed_ = true; | 66 | parsed_ = true; |
65 | assembled_ = false; | 67 | assembled_ = false; |
66 | } | 68 | } |
67 | 69 | ||
68 | DateValue::DateValue(const QDate & d) | 70 | DateValue::DateValue(const QDate & d) |
69 | : Value (), | 71 | : Value (), |
70 | year_ (d.year()), | 72 | year_ (d.year()), |
71 | month_ (d.month()), | 73 | month_ (d.month()), |
72 | day_ (d.day()), | 74 | day_ (d.day()), |
73 | hasTime_(false) | 75 | hasTime_(false) |
74 | { | 76 | { |
75 | parsed_ = true; | 77 | parsed_ = true; |
76 | assembled_ = false; | 78 | assembled_ = false; |
77 | } | 79 | } |
78 | 80 | ||
79 | DateValue::DateValue(const QDateTime & d) | 81 | DateValue::DateValue(const QDateTime & d) |
80 | : Value (), | 82 | : Value (), |
81 | year_ (d.date().year()), | 83 | year_ (d.date().year()), |
82 | month_ (d.date().month()), | 84 | month_ (d.date().month()), |
83 | day_ (d.date().day()), | 85 | day_ (d.date().day()), |
84 | hour_ (d.time().hour()), | 86 | hour_ (d.time().hour()), |
85 | minute_ (d.time().minute()), | 87 | minute_ (d.time().minute()), |
86 | second_ (d.time().second()), | 88 | second_ (d.time().second()), |
87 | hasTime_(true) | 89 | hasTime_(true) |
88 | { | 90 | { |
89 | parsed_ = true; | 91 | parsed_ = true; |
90 | assembled_ = false; | 92 | assembled_ = false; |
91 | } | 93 | } |
92 | 94 | ||
93 | DateValue::DateValue(const DateValue & x) | 95 | DateValue::DateValue(const DateValue & x) |
94 | :Value(x) | 96 | :Value(x) |
95 | { | 97 | { |
96 | year_ = x.year_; | 98 | year_ = x.year_; |
97 | month_ = x.month_; | 99 | month_ = x.month_; |
98 | day_ = x.day_; | 100 | day_ = x.day_; |
99 | hour_ = x.hour_; | 101 | hour_ = x.hour_; |
100 | minute_ = x.minute_; | 102 | minute_ = x.minute_; |
101 | second_ = x.second_; | 103 | second_ = x.second_; |
102 | zoneHour_ = x.zoneHour_; | 104 | zoneHour_ = x.zoneHour_; |
103 | zoneMinute_ = x.zoneMinute_; | 105 | zoneMinute_ = x.zoneMinute_; |
104 | secFrac_ = x.secFrac_; | 106 | secFrac_ = x.secFrac_; |
105 | hasTime_ = x.hasTime_; | 107 | hasTime_ = x.hasTime_; |
106 | } | 108 | } |
107 | 109 | ||
108 | DateValue::DateValue(const QCString & s) | 110 | DateValue::DateValue(const Q3CString & s) |
109 | :Value(s) | 111 | :Value(s) |
110 | { | 112 | { |
111 | } | 113 | } |
112 | 114 | ||
113 | DateValue & | 115 | DateValue & |
114 | DateValue::operator = (DateValue & x) | 116 | DateValue::operator = (DateValue & x) |
115 | { | 117 | { |
116 | if (*this == x) return *this; | 118 | if (*this == x) return *this; |
117 | 119 | ||
118 | Value::operator = (x); | 120 | Value::operator = (x); |
119 | return *this; | 121 | return *this; |
120 | } | 122 | } |
121 | 123 | ||
122 | DateValue & | 124 | DateValue & |
123 | DateValue::operator = (const QCString & s) | 125 | DateValue::operator = (const Q3CString & s) |
124 | { | 126 | { |
125 | Value::operator = (s); | 127 | Value::operator = (s); |
126 | return *this; | 128 | return *this; |
127 | } | 129 | } |
128 | 130 | ||
129 | bool | 131 | bool |
130 | DateValue::operator == (DateValue & x) | 132 | DateValue::operator == (DateValue & x) |
131 | { | 133 | { |
132 | x.parse(); | 134 | x.parse(); |
133 | return false; | 135 | return false; |
134 | } | 136 | } |
135 | 137 | ||
136 | DateValue::~DateValue() | 138 | DateValue::~DateValue() |
137 | { | 139 | { |
138 | } | 140 | } |
139 | 141 | ||
140 | DateValue * | 142 | DateValue * |
141 | DateValue::clone() | 143 | DateValue::clone() |
142 | { | 144 | { |
143 | return new DateValue( *this ); | 145 | return new DateValue( *this ); |
144 | } | 146 | } |
145 | 147 | ||
146 | void | 148 | void |
147 | DateValue::_parse() | 149 | DateValue::_parse() |
148 | { | 150 | { |
149 | vDebug("DateValue::_parse()"); | 151 | vDebug("DateValue::_parse()"); |
150 | 152 | ||
151 | // date = date-full-year ["-"] date-month ["-"] date-mday | 153 | // date = date-full-year ["-"] date-month ["-"] date-mday |
152 | // time = time-hour [":"] time-minute [":"] time-second [":"] | 154 | // time = time-hour [":"] time-minute [":"] time-second [":"] |
153 | // [time-secfrac] [time-zone] | 155 | // [time-secfrac] [time-zone] |
154 | 156 | ||
155 | int timeSep = strRep_.find('T'); | 157 | int timeSep = strRep_.find('T'); |
156 | 158 | ||
157 | QCString dateStr; | 159 | Q3CString dateStr; |
158 | QCString timeStr; | 160 | Q3CString timeStr; |
159 | 161 | ||
160 | if (timeSep == -1) { | 162 | if (timeSep == -1) { |
161 | 163 | ||
162 | dateStr = strRep_; | 164 | dateStr = strRep_; |
163 | vDebug("Has date string \"" + dateStr + "\""); | 165 | vDebug("Has date string \"" + dateStr + "\""); |
164 | 166 | ||
165 | } else { | 167 | } else { |
166 | 168 | ||
167 | dateStr = strRep_.left(timeSep); | 169 | dateStr = strRep_.left(timeSep); |
168 | vDebug("Has date string \"" + dateStr + "\""); | 170 | vDebug("Has date string \"" + dateStr + "\""); |
169 | 171 | ||
170 | timeStr = strRep_.mid(timeSep + 1); | 172 | timeStr = strRep_.mid(timeSep + 1); |
171 | vDebug("Has time string \"" + timeStr + "\""); | 173 | vDebug("Has time string \"" + timeStr + "\""); |
172 | } | 174 | } |
173 | 175 | ||
174 | /////////////////////////////////////////////////////////////// DATE | 176 | /////////////////////////////////////////////////////////////// DATE |
175 | 177 | ||
176 | dateStr.replace(QRegExp("-"), ""); | 178 | dateStr.replace("-", ""); |
177 | 179 | ||
178 | kdDebug(5710) << "dateStr: " << dateStr << endl; | 180 | kdDebug(5710) << "dateStr: " << dateStr << endl; |
179 | 181 | ||
180 | year_= dateStr.left(4).toInt(); | 182 | year_= dateStr.left(4).toInt(); |
181 | month_= dateStr.mid(4, 2).toInt(); | 183 | month_= dateStr.mid(4, 2).toInt(); |
182 | day_= dateStr.right(2).toInt(); | 184 | day_= dateStr.right(2).toInt(); |
183 | 185 | ||
184 | if (timeSep == -1) { | 186 | if (timeSep == -1) { |
185 | hasTime_ = false; | 187 | hasTime_ = false; |
186 | return; // No time, done. | 188 | return; // No time, done. |
187 | } | 189 | } |
188 | else | 190 | else |
189 | hasTime_ = true; | 191 | hasTime_ = true; |
190 | 192 | ||
191 | /////////////////////////////////////////////////////////////// TIME | 193 | /////////////////////////////////////////////////////////////// TIME |
192 | 194 | ||
193 | /////////////////////////////////////////////////////////////// ZONE | 195 | /////////////////////////////////////////////////////////////// ZONE |
194 | 196 | ||
195 | int zoneSep = timeStr.find('Z'); | 197 | int zoneSep = timeStr.find('Z'); |
196 | 198 | ||
197 | if (zoneSep != -1 && timeStr.length() - zoneSep > 3) { | 199 | if (zoneSep != -1 && timeStr.length() - zoneSep > 3) { |
198 | 200 | ||
199 | QCString zoneStr(timeStr.mid(zoneSep + 1)); | 201 | Q3CString zoneStr(timeStr.mid(zoneSep + 1)); |
200 | vDebug("zoneStr == " + zoneStr); | 202 | vDebug("zoneStr == " + zoneStr); |
201 | 203 | ||
202 | zonePositive_= (zoneStr[0] == '+'); | 204 | zonePositive_= (zoneStr[0] == '+'); |
203 | zoneHour_ = zoneStr.mid(1, 2).toInt(); | 205 | zoneHour_ = zoneStr.mid(1, 2).toInt(); |
204 | zoneMinute_ = zoneStr.right(2).toInt(); | 206 | zoneMinute_ = zoneStr.right(2).toInt(); |
205 | 207 | ||
206 | timeStr.remove(zoneSep, timeStr.length() - zoneSep); | 208 | timeStr.remove(zoneSep, timeStr.length() - zoneSep); |
207 | } | 209 | } |
208 | 210 | ||
209 | //////////////////////////////////////////////////// SECOND FRACTION | 211 | //////////////////////////////////////////////////// SECOND FRACTION |
210 | 212 | ||
211 | int secFracSep = timeStr.findRev(','); | 213 | int secFracSep = timeStr.findRev(','); |
212 | 214 | ||
213 | if (secFracSep != -1 && zoneSep != -1) { // zoneSep checked to avoid errors. | 215 | if (secFracSep != -1 && zoneSep != -1) { // zoneSep checked to avoid errors. |
214 | QCString quirkafleeg = "0." + timeStr.mid(secFracSep + 1, zoneSep); | 216 | Q3CString quirkafleeg = "0." + timeStr.mid(secFracSep + 1, zoneSep); |
215 | secFrac_ = quirkafleeg.toDouble(); | 217 | secFrac_ = quirkafleeg.toDouble(); |
216 | } | 218 | } |
217 | 219 | ||
218 | /////////////////////////////////////////////////////////////// HMS | 220 | /////////////////////////////////////////////////////////////// HMS |
219 | 221 | ||
220 | timeStr.replace(QRegExp(":"), ""); | 222 | timeStr.replace(":", ""); |
221 | 223 | ||
222 | hour_= timeStr.left(2).toInt(); | 224 | hour_= timeStr.left(2).toInt(); |
223 | minute_= timeStr.mid(2, 2).toInt(); | 225 | minute_= timeStr.mid(2, 2).toInt(); |
224 | second_= timeStr.mid(4, 2).toInt(); | 226 | second_= timeStr.mid(4, 2).toInt(); |
225 | } | 227 | } |
226 | 228 | ||
227 | void | 229 | void |
228 | DateValue::_assemble() | 230 | DateValue::_assemble() |
229 | { | 231 | { |
230 | vDebug("DateValue::_assemble"); | 232 | vDebug("DateValue::_assemble"); |
231 | 233 | ||
232 | QCString year; | 234 | Q3CString year; |
233 | QCString month; | 235 | Q3CString month; |
234 | QCString day; | 236 | Q3CString day; |
235 | 237 | ||
236 | year.setNum( year_ ); | 238 | year.setNum( year_ ); |
237 | month.setNum( month_ ); | 239 | month.setNum( month_ ); |
238 | day.setNum( day_ ); | 240 | day.setNum( day_ ); |
239 | 241 | ||
240 | if ( month.length() < 2 ) month.prepend( "0" ); | 242 | if ( month.length() < 2 ) month.prepend( "0" ); |
241 | if ( day.length() < 2 ) day.prepend( "0" ); | 243 | if ( day.length() < 2 ) day.prepend( "0" ); |
242 | 244 | ||
243 | strRep_ = year + '-' + month + '-' + day; | 245 | strRep_ = year + '-' + month + '-' + day; |
244 | 246 | ||
245 | if ( hasTime_ ) { | 247 | if ( hasTime_ ) { |
246 | QCString hour; | 248 | Q3CString hour; |
247 | QCString minute; | 249 | Q3CString minute; |
248 | QCString second; | 250 | Q3CString second; |
249 | 251 | ||
250 | hour.setNum( hour_ ); | 252 | hour.setNum( hour_ ); |
251 | minute.setNum( minute_ ); | 253 | minute.setNum( minute_ ); |
252 | second.setNum( second_ ); | 254 | second.setNum( second_ ); |
253 | 255 | ||
254 | if ( hour.length() < 2 ) hour.prepend( "0" ); | 256 | if ( hour.length() < 2 ) hour.prepend( "0" ); |
255 | if ( minute.length() < 2 ) minute.prepend( "0" ); | 257 | if ( minute.length() < 2 ) minute.prepend( "0" ); |
256 | if ( second.length() < 2 ) second.prepend( "0" ); | 258 | if ( second.length() < 2 ) second.prepend( "0" ); |
257 | 259 | ||
258 | strRep_ += 'T' + hour + ':' + minute + ':' + second + 'Z'; | 260 | strRep_ += 'T' + hour + ':' + minute + ':' + second + 'Z'; |
259 | } | 261 | } |
260 | } | 262 | } |
261 | 263 | ||
262 | unsigned int | 264 | unsigned int |
263 | DateValue::year() | 265 | DateValue::year() |
264 | { | 266 | { |
265 | parse(); | 267 | parse(); |
266 | return year_; | 268 | return year_; |
267 | } | 269 | } |
268 | 270 | ||
269 | unsigned int | 271 | unsigned int |
270 | DateValue::month() | 272 | DateValue::month() |
271 | { | 273 | { |
272 | parse(); | 274 | parse(); |
273 | return month_; | 275 | return month_; |
274 | } | 276 | } |
275 | 277 | ||
276 | unsigned int | 278 | unsigned int |
277 | DateValue::day() | 279 | DateValue::day() |
278 | { | 280 | { |
279 | parse(); | 281 | parse(); |
280 | return day_; | 282 | return day_; |
281 | } | 283 | } |
282 | unsigned int | 284 | unsigned int |
283 | DateValue::hour() | 285 | DateValue::hour() |
284 | { | 286 | { |
285 | parse(); | 287 | parse(); |
286 | return hour_; | 288 | return hour_; |
287 | } | 289 | } |
288 | 290 | ||
289 | unsigned int | 291 | unsigned int |
290 | DateValue::minute() | 292 | DateValue::minute() |
291 | { | 293 | { |
292 | parse(); | 294 | parse(); |
293 | return minute_; | 295 | return minute_; |
294 | } | 296 | } |
295 | 297 | ||
296 | unsigned int | 298 | unsigned int |
297 | DateValue::second() | 299 | DateValue::second() |
298 | { | 300 | { |
299 | parse(); | 301 | parse(); |
300 | return second_; | 302 | return second_; |
301 | } | 303 | } |
302 | 304 | ||
303 | double | 305 | double |
304 | DateValue::secondFraction() | 306 | DateValue::secondFraction() |
305 | { | 307 | { |
306 | parse(); | 308 | parse(); |
307 | return secFrac_; | 309 | return secFrac_; |
308 | } | 310 | } |
309 | 311 | ||
310 | bool | 312 | bool |
311 | DateValue::zonePositive() | 313 | DateValue::zonePositive() |
312 | { | 314 | { |
313 | parse(); | 315 | parse(); |
314 | return zonePositive_; | 316 | return zonePositive_; |
315 | } | 317 | } |
316 | 318 | ||
317 | unsigned int | 319 | unsigned int |
318 | DateValue::zoneHour() | 320 | DateValue::zoneHour() |
319 | { | 321 | { |
320 | parse(); | 322 | parse(); |
321 | return zoneHour_; | 323 | return zoneHour_; |
322 | } | 324 | } |
323 | 325 | ||
324 | unsigned int | 326 | unsigned int |
325 | DateValue::zoneMinute() | 327 | DateValue::zoneMinute() |
326 | { | 328 | { |
327 | parse(); | 329 | parse(); |
328 | return zoneMinute_; | 330 | return zoneMinute_; |
329 | } | 331 | } |
330 | 332 | ||
331 | void | 333 | void |
332 | DateValue::setYear(unsigned int i) | 334 | DateValue::setYear(unsigned int i) |
333 | { | 335 | { |
334 | year_ = i; | 336 | year_ = i; |
335 | assembled_ = false; | 337 | assembled_ = false; |
336 | } | 338 | } |
337 | 339 | ||
338 | void | 340 | void |
339 | DateValue::setMonth(unsigned int i) | 341 | DateValue::setMonth(unsigned int i) |
340 | { | 342 | { |
341 | month_ = i; | 343 | month_ = i; |
342 | assembled_ = false; | 344 | assembled_ = false; |
343 | } | 345 | } |
344 | 346 | ||