|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "agsindexkey.h" |
|
17 #include "agmsimpleentry.h" |
|
18 #include "agmdate.h" |
|
19 |
|
20 // ---------------------------------TAgnKeyDate------------------------------ |
|
21 |
|
22 TAgnKeyDate::TAgnKeyDate(const MAgnCalendarTimeMode::TTimeMode aTimeMode) |
|
23 : TAgnKeyBase<CAgnSimpleEntry,TTime>(), |
|
24 iTimeMode(aTimeMode) |
|
25 { |
|
26 __ASSERT_DEBUG(iTimeMode == MAgnCalendarTimeMode::EFixedUtc || iTimeMode == MAgnCalendarTimeMode::EFloating, User::Invariant()); |
|
27 } |
|
28 |
|
29 void TAgnKeyDate::SetValueL(const TTime& aDate) |
|
30 // |
|
31 // set the key value that will be used by search |
|
32 // |
|
33 { |
|
34 if(iTimeMode == MAgnCalendarTimeMode::EFixedUtc) |
|
35 { |
|
36 iSearchKeyValue.SetLocalL(aDate); |
|
37 } |
|
38 else // we can assume iTimeMode == MAgnCalendarTimeMode::EFloating because of the |
|
39 // assert in the TAgnKeyDate constructor. |
|
40 { |
|
41 iSearchKeyValue.SetFloatingL(aDate); |
|
42 } |
|
43 } |
|
44 |
|
45 TInt TAgnKeyDate::Compare(const CAgnSimpleEntry* aEntry) const |
|
46 // |
|
47 // compare entry with search value |
|
48 // |
|
49 { |
|
50 // Note that undated entries will return a key value of |
|
51 // AgnDateTime::MaxDate() since we want them to have |
|
52 // a key value larger than all dated entries. |
|
53 // |
|
54 TTime entryTime; |
|
55 TTime searchKeyTime; |
|
56 if (iTimeMode == MAgnCalendarTimeMode::EFixedUtc) |
|
57 { |
|
58 entryTime = GetKeyValueUtcL(aEntry); |
|
59 searchKeyTime = iSearchKeyValue.UtcL(); |
|
60 } |
|
61 else // we can assume iTimeMode == MAgnCalendarTimeMode::EFloating because of the |
|
62 // assert in the TAgnKeyDate constructor. |
|
63 { |
|
64 entryTime = GetKeyValueL(aEntry); |
|
65 searchKeyTime = iSearchKeyValue.LocalL(); |
|
66 } |
|
67 |
|
68 if (searchKeyTime == Time::NullTTime()) |
|
69 { |
|
70 searchKeyTime = Time::MaxTTime(); |
|
71 } |
|
72 |
|
73 if (entryTime == searchKeyTime ) |
|
74 { |
|
75 return (0); |
|
76 } |
|
77 |
|
78 return entryTime < searchKeyTime ? -1 : 1; |
|
79 } |
|
80 |
|
81 TInt TAgnKeyDate::Compare(const CAgnSimpleEntry* aLeft, const CAgnSimpleEntry* aRight) const |
|
82 // |
|
83 // Compare two entries |
|
84 // |
|
85 { |
|
86 // Note that undated entries will return a key value of |
|
87 // AgnDateTime::MaxDate() since we want them to have |
|
88 // a key value larger than all dated entries. |
|
89 // |
|
90 TTime leftStart; |
|
91 TTime rightStart; |
|
92 |
|
93 if (iTimeMode == MAgnCalendarTimeMode::EFixedUtc) |
|
94 { |
|
95 leftStart = GetKeyValueUtcL(aLeft); |
|
96 rightStart = GetKeyValueUtcL(aRight); |
|
97 } |
|
98 else // we can assume iTimeMode == MAgnCalendarTimeMode::EFloating because of the |
|
99 // assert in the TAgnKeyDate constructor. |
|
100 { |
|
101 leftStart = GetKeyValueL(aLeft); |
|
102 rightStart = GetKeyValueL(aRight); |
|
103 } |
|
104 |
|
105 if (leftStart == rightStart) |
|
106 { |
|
107 return (0); |
|
108 } |
|
109 |
|
110 return (leftStart < rightStart? -1 : 1); |
|
111 } |
|
112 |
|
113 |
|
114 TInt TAgnKeyDate::Compare(TInt aLeft,TInt aRight) const |
|
115 // |
|
116 // compare two entries that are at position aLeft and aRight in array |
|
117 // |
|
118 { |
|
119 |
|
120 CAgnSimpleEntry* LeftEntry = *(CAgnSimpleEntry**)At(aLeft); |
|
121 CAgnSimpleEntry* RightEntry = *(CAgnSimpleEntry**)At(aRight); |
|
122 |
|
123 if (aRight == -1 && RightEntry == NULL) |
|
124 { |
|
125 return Compare(LeftEntry); |
|
126 } |
|
127 |
|
128 return Compare(LeftEntry,RightEntry); |
|
129 } |
|
130 |
|
131 // ----------------------------TAgnKeyStartDate--------------------------------- |
|
132 |
|
133 TAgnKeyStartDate::TAgnKeyStartDate(const MAgnCalendarTimeMode::TTimeMode aTimeMode) |
|
134 : TAgnKeyDate(aTimeMode) |
|
135 { |
|
136 } |
|
137 |
|
138 TTime TAgnKeyStartDate::GetKeyValueL(const CAgnSimpleEntry* aEntry) const |
|
139 // |
|
140 // Return value of key of entry |
|
141 // |
|
142 { |
|
143 return aEntry->ValidFromTimeLocalL(); |
|
144 } |
|
145 |
|
146 TTime TAgnKeyStartDate::GetKeyValueUtcL(const CAgnSimpleEntry* aEntry) const |
|
147 // |
|
148 // Return value of key of entry (utc version of this function) |
|
149 // |
|
150 { |
|
151 return AgnDateTime::ConvertToUtcTimeL(GetKeyValueL(aEntry)); |
|
152 } |
|
153 |
|
154 |
|
155 // ----------------------------TAgnKeyRptDate----------------------------------- |
|
156 |
|
157 TAgnKeyRptDate::TAgnKeyRptDate(const MAgnCalendarTimeMode::TTimeMode aTimeMode) |
|
158 : TAgnKeyDate(aTimeMode) |
|
159 { |
|
160 } |
|
161 |
|
162 TTime TAgnKeyRptDate::GetKeyValueL(const CAgnSimpleEntry* aEntry) const |
|
163 // |
|
164 // Return value of key of entry |
|
165 // |
|
166 { |
|
167 return aEntry->ValidFromTimeLocalL(); |
|
168 } |
|
169 |
|
170 TTime TAgnKeyRptDate::GetKeyValueUtcL(const CAgnSimpleEntry* aEntry) const |
|
171 // |
|
172 // Return value of key of entry (utc version of this function) |
|
173 // |
|
174 { |
|
175 return AgnDateTime::ConvertToUtcTimeL(GetKeyValueL(aEntry)); |
|
176 } |
|
177 |
|
178 |
|
179 // ----------------------------TAgnKeyTodoNonRptDate---------------------------- |
|
180 |
|
181 TAgnKeyTodoNonRptDate::TAgnKeyTodoNonRptDate(const MAgnCalendarTimeMode::TTimeMode aTimeMode) |
|
182 : TAgnKeyDate(aTimeMode) |
|
183 { |
|
184 } |
|
185 |
|
186 /** Return value of key of entry |
|
187 */ |
|
188 TTime TAgnKeyTodoNonRptDate::GetKeyValueL(const CAgnSimpleEntry* aEntry) const |
|
189 { |
|
190 const TTime KCompletedDateUtc = aEntry->CompletedDateUtc(); |
|
191 if (KCompletedDateUtc != Time::NullTTime()) |
|
192 { |
|
193 return AgnDateTime::ConvertToLocalTimeL(KCompletedDateUtc); |
|
194 } |
|
195 |
|
196 if ( ! aEntry->EndTime().IsSet()) // if its undated |
|
197 { |
|
198 return iUndatedTodoTime; |
|
199 } |
|
200 |
|
201 return aEntry->EndTime().LocalL(); |
|
202 } |
|
203 |
|
204 /** Return value of key of entry (utc version of this function) |
|
205 */ |
|
206 TTime TAgnKeyTodoNonRptDate::GetKeyValueUtcL(const CAgnSimpleEntry* aEntry) const |
|
207 { |
|
208 |
|
209 TTime completedDate = aEntry->CompletedDateUtc(); |
|
210 if (completedDate != Time::NullTTime()) |
|
211 { |
|
212 return completedDate; |
|
213 } |
|
214 |
|
215 if ( ! aEntry->EndTime().IsSet()) // if its undated |
|
216 { |
|
217 return AgnDateTime::ConvertToUtcTimeL(iUndatedTodoTime); |
|
218 } |
|
219 |
|
220 return aEntry->EndTime().UtcL(); |
|
221 } |