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