• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

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

tdeabc

Skip menu "tdeabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.8.8
This website is maintained by Timothy Pearson.