|
1 /* |
|
2 * Copyright (c) 2005-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Utility class and constants used by Iptv application.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 |
|
23 #include "ciptvxmldatetime.h" |
|
24 #include "ciptvxmlconsts.h" |
|
25 #include "IptvDebug.h" |
|
26 |
|
27 _LIT( KIptvEmptyDes, "" ); |
|
28 |
|
29 // -------------------------------------------------------------------------- |
|
30 // Parse GMT time. |
|
31 // -------------------------------------------------------------------------- |
|
32 // |
|
33 void CIptvXmlDateTime::ParseGmtL( const HBufC* aBuffer, TTime& aTime ) |
|
34 { |
|
35 IPTVLOGSTRING_LOW_LEVEL( |
|
36 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL" ); |
|
37 |
|
38 TBool success( EFalse ); |
|
39 TInt index( KErrNotFound ); |
|
40 TInt gmtIndex( KErrNotFound ); |
|
41 TInt gmtLength( KErrNotFound ); |
|
42 |
|
43 if ( !aBuffer ) |
|
44 { |
|
45 User::Leave( KErrArgument ); |
|
46 } |
|
47 else |
|
48 { |
|
49 TInt bufLength = aBuffer->Length(); |
|
50 index = aBuffer->Locate( ',' ); |
|
51 gmtIndex = aBuffer->LocateReverse( ' ' ); |
|
52 gmtLength = bufLength - gmtIndex; |
|
53 |
|
54 if ( ( index != KErrNotFound ) && ( gmtIndex != KErrNotFound ) ) |
|
55 { |
|
56 success = ETrue; |
|
57 } |
|
58 } |
|
59 |
|
60 TInt parseStatus( KErrNone ); |
|
61 |
|
62 if ( success ) |
|
63 { |
|
64 // Time shifting from GMT |
|
65 TInt hourShift = 0; |
|
66 |
|
67 // Get zone |
|
68 HBufC* zone = HBufC::NewLC( gmtLength ); |
|
69 TPtr16 zonePtr = zone->Des(); |
|
70 zonePtr.Copy( aBuffer->Mid( gmtIndex, gmtLength ) ); |
|
71 zonePtr.Trim(); |
|
72 |
|
73 // Get hour shift from time zone. |
|
74 hourShift = GetHourShiftFromZone( zonePtr ); |
|
75 IPTVLOGSTRING2_LOW_LEVEL( |
|
76 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL Hour shift from time zone = %d", |
|
77 hourShift ); |
|
78 |
|
79 // Do we increment or decrement from time zone. |
|
80 gmtLength = zonePtr.Length(); |
|
81 TBuf<KIptvShiftNumberMaxCount > temp; |
|
82 TBool add = ETrue; |
|
83 for ( TInt i = 0; i < gmtLength; i++ ) |
|
84 { |
|
85 //lint -e{961} Else block not needed, other characters ignored. |
|
86 if ( TChar( zonePtr[i] ).IsDigit() ) |
|
87 { |
|
88 if ( KIptvShiftNumberMaxCount > temp.Length() ) |
|
89 { |
|
90 temp.Append( zonePtr[i] ); |
|
91 } |
|
92 } |
|
93 else if ( zonePtr[i] == '+' ) |
|
94 { |
|
95 add = ETrue; |
|
96 } |
|
97 else if ( zonePtr[i] == '-' ) |
|
98 { |
|
99 add = EFalse; |
|
100 } |
|
101 } |
|
102 |
|
103 // Additional shift |
|
104 TInt additionalHourShift = 0; |
|
105 TInt additionalMinuteShift = 0; |
|
106 TInt shiftLength = temp.Length(); |
|
107 TBuf<KIptvHourNumberCount> hs; |
|
108 TBuf<KIptvMinuteNumberCount> ms; |
|
109 |
|
110 //lint -e{961} Else block not needed, default is empty. |
|
111 if ( shiftLength == KIptvShiftNumberCountH ) |
|
112 { |
|
113 hs.Append( temp[KIptvShiftHourHighIndex] ); |
|
114 } |
|
115 else if ( shiftLength == KIptvShiftNumberCountHH ) |
|
116 { |
|
117 hs.Append( temp[KIptvShiftHourHighIndex] ); |
|
118 hs.Append( temp[KIptvShiftHourLowIndex] ); |
|
119 } |
|
120 else if ( shiftLength == KIptvShiftNumberCountHHM ) |
|
121 { |
|
122 hs.Append( temp[KIptvShiftHourHighIndex] ); |
|
123 hs.Append( temp[KIptvShiftHourLowIndex] ); |
|
124 ms.Append( temp[KIptvShiftMinuteHighIndex] ); |
|
125 } |
|
126 else if ( shiftLength == KIptvShiftNumberCountHHMM ) |
|
127 { |
|
128 hs.Append( temp[KIptvShiftHourHighIndex] ); |
|
129 hs.Append( temp[KIptvShiftHourLowIndex] ); |
|
130 ms.Append( temp[KIptvShiftMinuteHighIndex] ); |
|
131 ms.Append( temp[KIptvShiftMinuteLowIndex] ); |
|
132 } |
|
133 |
|
134 if ( hs.Compare( KIptvEmptyDes ) != 0 ) |
|
135 { |
|
136 TLex hlex( hs ); |
|
137 hlex.Val( additionalHourShift ); |
|
138 } |
|
139 |
|
140 if ( ms.Compare( KIptvEmptyDes ) != 0 ) |
|
141 { |
|
142 TLex mlex( ms ); |
|
143 mlex.Val( additionalMinuteShift ); |
|
144 } |
|
145 |
|
146 hourShift = hourShift + additionalHourShift; |
|
147 |
|
148 TTimeIntervalHours hourInterval( hourShift ); |
|
149 TTimeIntervalMinutes minuteInterval( additionalMinuteShift ); |
|
150 CleanupStack::PopAndDestroy( zone ); |
|
151 zone = NULL; |
|
152 |
|
153 // Date |
|
154 TInt dateLength = gmtIndex - index; |
|
155 HBufC* date = HBufC::NewLC( dateLength ); |
|
156 TPtr16 datePtr = date->Des(); |
|
157 datePtr.Copy( aBuffer->Mid( index + 1, dateLength - 1 ) ); |
|
158 datePtr.Trim(); |
|
159 |
|
160 // Convert english strings "jan", "feb" etc. to local "tam", "hel" etc. |
|
161 // Needed because TTime always performs locale specific conversion. |
|
162 HBufC* fixedDate = ConvertMonthStringToLocaleL( datePtr ); |
|
163 CleanupStack::PushL( fixedDate ); |
|
164 |
|
165 // Parse the actual date string. |
|
166 parseStatus = aTime.Parse( *fixedDate ); |
|
167 CleanupStack::PopAndDestroy( fixedDate ); |
|
168 fixedDate = NULL; |
|
169 CleanupStack::PopAndDestroy( date ); |
|
170 date = NULL; |
|
171 |
|
172 if ( parseStatus >= 0 ) |
|
173 { |
|
174 |
|
175 #ifdef _DEBUG |
|
176 const TInt KIptvDebugBufLen( 100 ); |
|
177 TBuf<KIptvDebugBufLen> datePrint; |
|
178 _LIT( KIptvDatePrint, "%D%M%Y%/0%1%/1%2%/2%3%/3" ); |
|
179 aTime.FormatL( datePrint, KIptvDatePrint ); |
|
180 IPTVLOGSTRING2_LOW_LEVEL( |
|
181 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- Publish date : %S", |
|
182 &datePrint ); |
|
183 |
|
184 TBuf<KIptvDebugBufLen> timePrint; |
|
185 _LIT( KIptvTimePrint, "%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B" ); |
|
186 aTime.FormatL( timePrint, KIptvTimePrint ); |
|
187 IPTVLOGSTRING2_LOW_LEVEL( |
|
188 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- Publish time : %S", |
|
189 &timePrint ); |
|
190 |
|
191 IPTVLOGSTRING_LOW_LEVEL( |
|
192 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- In universal time" ); |
|
193 #endif |
|
194 |
|
195 if ( add ) |
|
196 { |
|
197 IPTVLOGSTRING2_LOW_LEVEL( |
|
198 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- decrement %d hours", |
|
199 hourShift ); |
|
200 IPTVLOGSTRING2_LOW_LEVEL( |
|
201 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- decrement %d minutes", |
|
202 additionalMinuteShift ); |
|
203 aTime -= hourInterval; |
|
204 aTime -= minuteInterval; |
|
205 } |
|
206 else |
|
207 { |
|
208 IPTVLOGSTRING2_LOW_LEVEL( |
|
209 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- increment %d hours", |
|
210 hourShift ); |
|
211 IPTVLOGSTRING2_LOW_LEVEL( |
|
212 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- increment %d minutes", |
|
213 additionalMinuteShift ); |
|
214 aTime += hourInterval; |
|
215 aTime += minuteInterval; |
|
216 } |
|
217 |
|
218 #ifdef _DEBUG |
|
219 aTime.FormatL( datePrint, KIptvDatePrint ); |
|
220 IPTVLOGSTRING2_LOW_LEVEL( |
|
221 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- Publish date : %S", |
|
222 &datePrint ); |
|
223 |
|
224 aTime.FormatL( timePrint, KIptvTimePrint ); |
|
225 IPTVLOGSTRING2_LOW_LEVEL( |
|
226 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- Publish time : %S", |
|
227 &timePrint ); |
|
228 #endif |
|
229 |
|
230 } |
|
231 else |
|
232 { |
|
233 success = EFalse; |
|
234 } |
|
235 } |
|
236 |
|
237 // On case failure, return zero time. |
|
238 if ( !success ) |
|
239 { |
|
240 TTime ztime( TInt64( 0 ) ); |
|
241 aTime = ztime; |
|
242 |
|
243 #ifdef _DEBUG |
|
244 |
|
245 switch ( parseStatus ) |
|
246 { |
|
247 case KErrGeneral: |
|
248 IPTVLOGSTRING_LOW_LEVEL( |
|
249 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- parse error KErrGeneral" ); |
|
250 break; |
|
251 |
|
252 case KErrNotSupported: |
|
253 IPTVLOGSTRING_LOW_LEVEL( |
|
254 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- parse error KErrNotSupported" ); |
|
255 break; |
|
256 |
|
257 case KErrArgument: |
|
258 IPTVLOGSTRING_LOW_LEVEL( |
|
259 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- parse error KErrArgument" ); |
|
260 break; |
|
261 |
|
262 default: |
|
263 IPTVLOGSTRING_LOW_LEVEL( |
|
264 "RSS Plugin::CIptvXmlContentHandler::ParseGmtL -- parse error default" ); |
|
265 break; |
|
266 } |
|
267 #endif |
|
268 |
|
269 } |
|
270 } |
|
271 |
|
272 // -------------------------------------------------------------------------- |
|
273 // Parses hour shift value from time zone. |
|
274 // -------------------------------------------------------------------------- |
|
275 // |
|
276 TInt CIptvXmlDateTime::GetHourShiftFromZone( |
|
277 const TPtr16& aZone ) |
|
278 { |
|
279 IPTVLOGSTRING_LOW_LEVEL( |
|
280 "RSS Plugin::CIptvXmlContentHandler::GetHourShiftFromZone" ); |
|
281 |
|
282 TInt hourShift( KIptvTimeZoneShift_None ); |
|
283 |
|
284 if ( ( aZone.CompareF( KIptvTimeZone_GMT ) == 0 ) || |
|
285 ( aZone.CompareF( KIptvTimeZone_UT ) == 0 ) || |
|
286 ( aZone.CompareF( KIptvTimeZone_Z ) == 0 ) ) |
|
287 { |
|
288 hourShift = KIptvTimeZoneShift_Z; |
|
289 } |
|
290 else if ( aZone.CompareF( KIptvTimeZone_A ) == 0 ) |
|
291 { |
|
292 hourShift = KIptvTimeZoneShift_A; |
|
293 } |
|
294 else if ( aZone.CompareF( KIptvTimeZone_B ) == 0 ) |
|
295 { |
|
296 hourShift = KIptvTimeZoneShift_B; |
|
297 } |
|
298 else if ( aZone.CompareF( KIptvTimeZone_C ) == 0 ) |
|
299 { |
|
300 hourShift = KIptvTimeZoneShift_C; |
|
301 } |
|
302 else if ( ( aZone.CompareF( KIptvTimeZone_EDT ) == 0 ) || |
|
303 ( aZone.CompareF( KIptvTimeZone_D ) == 0 ) ) |
|
304 { |
|
305 hourShift = KIptvTimeZoneShift_D; |
|
306 } |
|
307 else if ( ( aZone.CompareF( KIptvTimeZone_EST ) == 0 ) || |
|
308 ( aZone.CompareF( KIptvTimeZone_CDT ) == 0 ) || |
|
309 ( aZone.CompareF( KIptvTimeZone_E ) == 0 ) ) |
|
310 { |
|
311 hourShift = KIptvTimeZoneShift_E; |
|
312 } |
|
313 else if ( ( aZone.CompareF( KIptvTimeZone_CST ) == 0 ) || |
|
314 ( aZone.CompareF( KIptvTimeZone_MDT ) == 0 ) || |
|
315 ( aZone.CompareF( KIptvTimeZone_F ) == 0 ) ) |
|
316 { |
|
317 hourShift = KIptvTimeZoneShift_F; |
|
318 } |
|
319 else if ( ( aZone.CompareF( KIptvTimeZone_MST ) == 0 ) || |
|
320 ( aZone.CompareF( KIptvTimeZone_PDT ) == 0 ) || |
|
321 ( aZone.CompareF( KIptvTimeZone_G ) == 0 ) ) |
|
322 { |
|
323 hourShift = KIptvTimeZoneShift_G; |
|
324 } |
|
325 else if ( ( aZone.CompareF( KIptvTimeZone_PST ) == 0 ) || |
|
326 ( aZone.CompareF( KIptvTimeZone_H ) == 0 ) ) |
|
327 { |
|
328 hourShift = KIptvTimeZoneShift_H; |
|
329 } |
|
330 else if ( aZone.CompareF( KIptvTimeZone_I ) == 0 ) |
|
331 { |
|
332 hourShift = KIptvTimeZoneShift_I; |
|
333 } |
|
334 else if ( aZone.CompareF( KIptvTimeZone_K ) == 0 ) |
|
335 { |
|
336 hourShift = KIptvTimeZoneShift_K; |
|
337 } |
|
338 else if ( aZone.CompareF( KIptvTimeZone_L ) == 0 ) |
|
339 { |
|
340 hourShift = KIptvTimeZoneShiftL; |
|
341 } |
|
342 else if ( aZone.CompareF( KIptvTimeZone_M ) == 0 ) |
|
343 { |
|
344 hourShift = KIptvTimeZoneShift_M; |
|
345 } |
|
346 else if ( aZone.CompareF( KIptvTimeZone_N ) == 0 ) |
|
347 { |
|
348 hourShift = KIptvTimeZoneShift_N; |
|
349 } |
|
350 else if ( aZone.CompareF( KIptvTimeZone_O ) == 0 ) |
|
351 { |
|
352 hourShift = KIptvTimeZoneShift_O; |
|
353 } |
|
354 else if ( aZone.CompareF( KIptvTimeZone_P ) == 0 ) |
|
355 { |
|
356 hourShift = KIptvTimeZoneShift_P; |
|
357 } |
|
358 else if ( aZone.CompareF( KIptvTimeZone_Q ) == 0 ) |
|
359 { |
|
360 hourShift = KIptvTimeZoneShift_Q; |
|
361 } |
|
362 else if ( aZone.CompareF( KIptvTimeZone_R ) == 0 ) |
|
363 { |
|
364 hourShift = KIptvTimeZoneShift_R; |
|
365 } |
|
366 else if ( aZone.CompareF( KIptvTimeZone_S ) == 0 ) |
|
367 { |
|
368 hourShift = KIptvTimeZoneShift_S; |
|
369 } |
|
370 else if ( aZone.CompareF( KIptvTimeZone_T ) == 0 ) |
|
371 { |
|
372 hourShift = KIptvTimeZoneShift_T; |
|
373 } |
|
374 else if ( aZone.CompareF( KIptvTimeZone_U ) == 0 ) |
|
375 { |
|
376 hourShift = KIptvTimeZoneShift_U; |
|
377 } |
|
378 else if ( aZone.CompareF( KIptvTimeZone_V ) == 0 ) |
|
379 { |
|
380 hourShift = KIptvTimeZoneShift_V; |
|
381 } |
|
382 else if ( aZone.CompareF( KIptvTimeZone_W ) == 0 ) |
|
383 { |
|
384 hourShift = KIptvTimeZoneShift_W; |
|
385 } |
|
386 else if ( aZone.CompareF( KIptvTimeZone_X ) == 0 ) |
|
387 { |
|
388 hourShift = KIptvTimeZoneShift_X; |
|
389 } |
|
390 else if ( aZone.CompareF( KIptvTimeZone_Y ) == 0 ) |
|
391 { |
|
392 hourShift = KIptvTimeZoneShift_Y; |
|
393 } |
|
394 else |
|
395 { |
|
396 hourShift = KIptvTimeZoneShift_None; |
|
397 } |
|
398 |
|
399 return hourShift; |
|
400 } |
|
401 |
|
402 // -------------------------------------------------------------------------- |
|
403 // Converts english month in date string to locale specific month string. |
|
404 // -------------------------------------------------------------------------- |
|
405 // |
|
406 HBufC* CIptvXmlDateTime::ConvertMonthStringToLocaleL( |
|
407 const TDesC& aDateString ) |
|
408 { |
|
409 IPTVLOGSTRING_LOW_LEVEL( |
|
410 "RSS Plugin::CIptvXmlContentHandler::ConvertMonthStringToLocaleL" ); |
|
411 |
|
412 HBufC* newString = |
|
413 HBufC::NewLC( aDateString.Length() + KMaxMonthNameAbb ); |
|
414 TInt monthIndex = KErrNotFound; |
|
415 TMonthNameAbb localMonth; |
|
416 |
|
417 *newString = aDateString; |
|
418 newString->Des().LowerCase(); |
|
419 |
|
420 // Find the month string and init matching locale specific string. |
|
421 if ( KErrNotFound != |
|
422 ( monthIndex = newString->Find( KIptvJan ) ) ) |
|
423 { |
|
424 localMonth.Set( EJanuary ); |
|
425 } |
|
426 else if ( KErrNotFound != |
|
427 ( monthIndex = newString->Find( KIptvFeb ) ) ) |
|
428 { |
|
429 localMonth.Set( EFebruary ); |
|
430 } |
|
431 else if ( KErrNotFound != |
|
432 ( monthIndex = newString->Find( KIptvMar ) ) ) |
|
433 { |
|
434 localMonth.Set( EMarch ); |
|
435 } |
|
436 else if ( KErrNotFound != |
|
437 ( monthIndex = newString->Find( KIptvApr ) ) ) |
|
438 { |
|
439 localMonth.Set( EApril ); |
|
440 } |
|
441 else if ( KErrNotFound != |
|
442 ( monthIndex = newString->Find( KIptvMay ) ) ) |
|
443 { |
|
444 localMonth.Set( EMay ); |
|
445 } |
|
446 else if ( KErrNotFound != |
|
447 ( monthIndex = newString->Find( KIptvJun ) ) ) |
|
448 { |
|
449 localMonth.Set( EJune ); |
|
450 } |
|
451 else if ( KErrNotFound != |
|
452 ( monthIndex = newString->Find( KIptvJul ) ) ) |
|
453 { |
|
454 localMonth.Set( EJuly ); |
|
455 } |
|
456 else if ( KErrNotFound != |
|
457 ( monthIndex = newString->Find( KIptvAug ) ) ) |
|
458 { |
|
459 localMonth.Set( EAugust ); |
|
460 } |
|
461 else if ( KErrNotFound != |
|
462 ( monthIndex = newString->Find( KIptvSep ) ) ) |
|
463 { |
|
464 localMonth.Set( ESeptember ); |
|
465 } |
|
466 else if ( KErrNotFound != |
|
467 ( monthIndex = newString->Find( KIptvOct ) ) ) |
|
468 { |
|
469 localMonth.Set( EOctober ); |
|
470 } |
|
471 else if ( KErrNotFound != |
|
472 ( monthIndex = newString->Find( KIptvNov ) ) ) |
|
473 { |
|
474 localMonth.Set( ENovember ); |
|
475 } |
|
476 else if ( KErrNotFound != |
|
477 ( monthIndex = newString->Find( KIptvDec ) ) ) |
|
478 { |
|
479 localMonth.Set( EDecember ); |
|
480 } |
|
481 else |
|
482 { |
|
483 CleanupStack::Pop( newString ); |
|
484 return newString; |
|
485 } |
|
486 |
|
487 // 3 = length of old month string. |
|
488 HBufC* temp = |
|
489 HBufC::NewLC( newString->Length() - |
|
490 ( monthIndex + KIptvMonthShortNameLen ) ); |
|
491 *temp = newString->Mid( monthIndex + KIptvMonthShortNameLen ); |
|
492 |
|
493 // Re-construct the string with new month name. |
|
494 newString->Des().SetLength( monthIndex ); |
|
495 newString->Des().Append( localMonth ); |
|
496 newString->Des().Append( *temp ); |
|
497 |
|
498 CleanupStack::PopAndDestroy( temp ); |
|
499 temp = NULL; |
|
500 CleanupStack::Pop( newString ); |
|
501 return newString; |
|
502 } |
|
503 |