-rw-r--r-- | kabc/vcard/UTCValue.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/kabc/vcard/UTCValue.cpp b/kabc/vcard/UTCValue.cpp new file mode 100644 index 0000000..374306c --- a/dev/null +++ b/kabc/vcard/UTCValue.cpp | |||
@@ -0,0 +1,110 @@ | |||
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 <VCardUTCValue.h> | ||
25 | |||
26 | #include <VCardValue.h> | ||
27 | |||
28 | using namespace VCARD; | ||
29 | |||
30 | UTCValue::UTCValue() | ||
31 | :Value() | ||
32 | { | ||
33 | } | ||
34 | |||
35 | UTCValue::UTCValue(const UTCValue & x) | ||
36 | : Value(x),positive_(x.positive_), hour_(x.hour_), minute_(x.minute_) | ||
37 | |||
38 | { | ||
39 | } | ||
40 | |||
41 | UTCValue::UTCValue(const QCString & s) | ||
42 | :Value(s) | ||
43 | { | ||
44 | } | ||
45 | |||
46 | UTCValue & | ||
47 | UTCValue::operator = (UTCValue & x) | ||
48 | { | ||
49 | if (*this == x) return *this; | ||
50 | |||
51 | positive_ = x.positive_; | ||
52 | hour_ = x.hour_; | ||
53 | minute_ = x.minute_; | ||
54 | |||
55 | Value::operator = (x); | ||
56 | return *this; | ||
57 | } | ||
58 | |||
59 | UTCValue & | ||
60 | UTCValue::operator = (const QCString & s) | ||
61 | { | ||
62 | Value::operator = (s); | ||
63 | return *this; | ||
64 | } | ||
65 | |||
66 | bool | ||
67 | UTCValue::operator == (UTCValue & x) | ||
68 | { | ||
69 | x.parse(); | ||
70 | |||
71 | if (positive_ != x.positive_) return false; | ||
72 | if (hour_ != x.hour_) return false; | ||
73 | if (minute_ != x.minute_) return false; | ||
74 | |||
75 | return true; | ||
76 | } | ||
77 | |||
78 | UTCValue::~UTCValue() | ||
79 | { | ||
80 | } | ||
81 | |||
82 | UTCValue * | ||
83 | UTCValue::clone() | ||
84 | { | ||
85 | return new UTCValue( *this ); | ||
86 | } | ||
87 | |||
88 | void | ||
89 | UTCValue::_parse() | ||
90 | { | ||
91 | if ( strRep_.isEmpty() ) | ||
92 | return; | ||
93 | |||
94 | positive_ = ( strRep_[0] == '+' ); | ||
95 | |||
96 | int colon = strRep_.find( ':' ); | ||
97 | |||
98 | if ( colon == -1 ) // Not valid. | ||
99 | return; | ||
100 | |||
101 | hour_= strRep_.mid( 1, 2 ).toInt(); | ||
102 | minute_= strRep_.right( 2 ).toInt(); | ||
103 | } | ||
104 | |||
105 | void | ||
106 | UTCValue::_assemble() | ||
107 | { | ||
108 | strRep_.sprintf( "%c%.2i:%.2i", (positive_ ? '+' : '-'), hour_, minute_ ); | ||
109 | } | ||
110 | |||