changeset 81 | 676b6116ca93 |
parent 0 | 2e3d3ce01487 |
78:175a0d824084 | 81:676b6116ca93 |
---|---|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
16 #include <s32buf.h> |
16 #include <s32buf.h> |
17 #include <vtzrules.h> |
17 #include <vtzrules.h> |
18 #include <tz.h> |
18 #include <tz.h> |
19 |
19 |
20 #include "tzrules.h" |
20 #include "tzrules.h" |
21 #include "OstTraceDefinitions.h" |
|
22 #ifdef OST_TRACE_COMPILER_IN_USE |
|
23 #include "vtzrulesTraces.h" |
|
24 #endif |
|
25 |
|
21 |
26 |
22 const TInt KDaysInTheWeek = 7; |
27 const TInt KDaysInTheWeek = 7; |
23 const TInt KTzRulesGranularity = 4; |
28 const TInt KTzRulesGranularity = 4; |
24 |
29 |
25 // |
30 // |
244 @publishedAll |
249 @publishedAll |
245 @released |
250 @released |
246 */ |
251 */ |
247 EXPORT_C TVTzActualisedRule TTzRule::ActualiseL(TInt aYear) const |
252 EXPORT_C TVTzActualisedRule TTzRule::ActualiseL(TInt aYear) const |
248 { |
253 { |
254 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, TTZRULE_ACTUALISEL_ENTRY, "TTzRule::ActualiseL Exit;aYear=%d", aYear ); |
|
255 |
|
249 TInt dayOfMonth = iDayOfMonth; |
256 TInt dayOfMonth = iDayOfMonth; |
250 TInt daysDifference = 0; |
257 TInt daysDifference = 0; |
251 TDay dayOfWeek(EMonday); |
258 TDay dayOfWeek(EMonday); |
252 |
259 |
253 TDateTime actualDateTime(aYear, |
260 TDateTime actualDateTime(aYear, |
334 actualTime = actualDateTime; |
341 actualTime = actualDateTime; |
335 |
342 |
336 TVTzActualisedRule tActRule(actualTime, |
343 TVTzActualisedRule tActRule(actualTime, |
337 iNewLocalTimeOffset, |
344 iNewLocalTimeOffset, |
338 static_cast<TTzTimeReference>(iTimeReference)); |
345 static_cast<TTzTimeReference>(iTimeReference)); |
346 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, TTZRULE_ACTUALISEL_EXIT, "TTzRule::ActualiseL Exit" ); |
|
339 return tActRule; |
347 return tActRule; |
340 } |
348 } |
341 |
349 |
342 // |
350 // |
343 // CTzRules |
351 // CTzRules |
708 @internalComponent |
716 @internalComponent |
709 @released |
717 @released |
710 */ |
718 */ |
711 void CTzRules::AddActualisedRulesL(CVTzActualisedRules& aActRules, TInt aYear) const |
719 void CTzRules::AddActualisedRulesL(CVTzActualisedRules& aActRules, TInt aYear) const |
712 { |
720 { |
721 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CTZRULES_ADDACTUALISEDRULESL_ENTRY, "CTzRules::AddActualisedRulesL Entry;aYear=%d", aYear ); |
|
722 |
|
713 const TInt count=iRules.Count(); |
723 const TInt count=iRules.Count(); |
714 const TTzRule* trule = NULL; |
724 const TTzRule* trule = NULL; |
715 |
725 |
716 const TTime KYearBegin(TDateTime(aYear, EJanuary, 0, 0, 0, 0, 0)); |
726 const TTime KYearBegin(TDateTime(aYear, EJanuary, 0, 0, 0, 0, 0)); |
717 const TTime KYearEnd(TDateTime(aYear + 1, EJanuary, 0, 0, 0, 0, 0)); |
727 const TTime KYearEnd(TDateTime(aYear + 1, EJanuary, 0, 0, 0, 0, 0)); |
787 aActRules.AddRuleL(tactRule); |
797 aActRules.AddRuleL(tactRule); |
788 } |
798 } |
789 } |
799 } |
790 } |
800 } |
791 } |
801 } |
802 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CTZRULES_ADDACTUALISEDRULESL_EXIT, "CTzRules::AddActualisedRulesL Exit" ); |
|
803 |
|
792 } |
804 } |
793 |
805 |
794 /** |
806 /** |
795 Get actualised rules for time zone rules. |
807 Get actualised rules for time zone rules. |
796 @param aActRules Actualised rules for time zone rules. |
808 @param aActRules Actualised rules for time zone rules. |
797 @publishedAll |
809 @publishedAll |
798 @released |
810 @released |
799 */ |
811 */ |
800 EXPORT_C void CTzRules::GetActualisedRulesL(CVTzActualisedRules& aActRules) const |
812 EXPORT_C void CTzRules::GetActualisedRulesL(CVTzActualisedRules& aActRules) const |
801 { |
813 { |
814 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CTZRULES_GETACTUALISEDRULESL_ENTRY, "CTzRules::GetActualisedRulesL Entry" ); |
|
815 |
|
802 // Always add the initial offset because there may not have been |
816 // Always add the initial offset because there may not have been |
803 // any rules to actualise before the actualised rules range specified |
817 // any rules to actualise before the actualised rules range specified |
804 TVTzActualisedRule tDefRule(TDateTime(iStartYear, EJanuary, 0, 0, 0, 0, 0), iInitialStdTimeOffset, ETzWallTimeReference); |
818 TVTzActualisedRule tDefRule(TDateTime(iStartYear, EJanuary, 0, 0, 0, 0, 0), iInitialStdTimeOffset, ETzWallTimeReference); |
805 aActRules.AddRuleL(tDefRule); |
819 aActRules.AddRuleL(tDefRule); |
806 |
820 |
856 { |
870 { |
857 AddActualisedRulesL(aActRules, timeSoFar.DateTime().Year()); |
871 AddActualisedRulesL(aActRules, timeSoFar.DateTime().Year()); |
858 } |
872 } |
859 } |
873 } |
860 } |
874 } |
875 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CTZRULES_GETACTUALISEDRULESL_EXIT, "CTzRules::GetActualisedRulesL Exit" ); |
|
876 |
|
861 } |
877 } |
862 |
878 |
863 /** |
879 /** |
864 Converts the received local time to UTC time. |
880 Converts the received local time to UTC time. |
865 @param aTime The time to convert. On return, this contains the converted time. |
881 @param aTime The time to convert. On return, this contains the converted time. |
905 @internalComponent |
921 @internalComponent |
906 @released |
922 @released |
907 */ |
923 */ |
908 EXPORT_C TInt CTzRules::GetOffsetL(const TTime& aTime, TTzTimeReference aTimeRef) const |
924 EXPORT_C TInt CTzRules::GetOffsetL(const TTime& aTime, TTzTimeReference aTimeRef) const |
909 { |
925 { |
926 OstTraceDefExt5(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CTZRULES_GETOFFSETL_ENTRY, "CTzRules::GetOffsetL Entry; atime:Year=%d;Month=%d;Day=%d;Hour=%d;Min=%d", aTime.DateTime().Year(), aTime.DateTime().Month(), aTime.DateTime().Day(), aTime.DateTime().Hour(), aTime.DateTime().Minute() ); |
|
927 OstTraceDefExt2( OST_TRACE_CATEGORY_DEBUG,TRACE_FLOW_PARAM, CTZRULES_GETOFFSETL_PARAM, "Parameters cont..Sec=%d;aTimerRef=%u", aTime.DateTime().Second(), aTimeRef ); |
|
928 |
|
910 if (iActualisedRulesCache) |
929 if (iActualisedRulesCache) |
911 { |
930 { |
912 TTime startTime(TDateTime(iActualisedRulesCache->StartYear(), EJanuary, 0, 0, 0, 0, 0)); |
931 TTime startTime(TDateTime(iActualisedRulesCache->StartYear(), EJanuary, 0, 0, 0, 0, 0)); |
913 TTime endTime(TDateTime(iActualisedRulesCache->EndYear() + 1, EJanuary, 0, 0, 0, 0, 0)); |
932 TTime endTime(TDateTime(iActualisedRulesCache->EndYear() + 1, EJanuary, 0, 0, 0, 0, 0)); |
914 |
933 |
929 { |
948 { |
930 delete iActualisedRulesCache; |
949 delete iActualisedRulesCache; |
931 iActualisedRulesCache = NULL; |
950 iActualisedRulesCache = NULL; |
932 User::LeaveIfError(leaveCode); |
951 User::LeaveIfError(leaveCode); |
933 } |
952 } |
953 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CTZRULES_GETOFFSETL_EXIT, "CTzRules::GetOffsetL Exit" ); |
|
954 |
|
934 |
955 |
935 return iActualisedRulesCache->GetOffsetFromRuleL(aTime, aTimeRef);; |
956 return iActualisedRulesCache->GetOffsetFromRuleL(aTime, aTimeRef);; |
936 } |
957 } |
937 |
958 |
938 /** |
959 /** |
1266 @publishedAll |
1287 @publishedAll |
1267 @released |
1288 @released |
1268 */ |
1289 */ |
1269 EXPORT_C TBool CVTzActualisedRules::IsDaylightSavingOn(TTime& aTime) const |
1290 EXPORT_C TBool CVTzActualisedRules::IsDaylightSavingOn(TTime& aTime) const |
1270 { |
1291 { |
1292 OstTraceDefExt5(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CVTZACTUALISEDRULES_ISDAYLIGHTSAVINGON_ENTRY, "CVTzActualisedRules::IsDaylightSavingOn Entry;aTime:Year=%d;Month=%d;Day=%d;Hour=%d;Min=%d", aTime.DateTime().Year(), aTime.DateTime().Month(), aTime.DateTime().Day(), aTime.DateTime().Hour(), aTime.DateTime().Minute()); |
|
1293 OstTraceDef1( OST_TRACE_CATEGORY_DEBUG,TRACE_FLOW_PARAM, CVTZACTUALISEDRULES_ISDAYLIGHTSAVINGON_PARAM, "Parameter cont..;Sec=%d", aTime.DateTime().Second() ); |
|
1294 |
|
1271 const TInt count = iRules.Count(); |
1295 const TInt count = iRules.Count(); |
1272 |
1296 |
1273 // ensure that there are rules |
1297 // ensure that there are rules |
1274 __ASSERT_ALWAYS((count > 0), RTz::Panic(RTz::EPanicTimeNotCoveredByRules)); |
1298 __ASSERT_ALWAYS((count > 0), RTz::Panic(RTz::EPanicTimeNotCoveredByRules)); |
1275 |
1299 |
1396 // found the matching rule on previous run through loop |
1420 // found the matching rule on previous run through loop |
1397 break; |
1421 break; |
1398 } |
1422 } |
1399 } |
1423 } |
1400 } |
1424 } |
1425 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CVTZACTUALISEDRULES_ISDAYLIGHTSAVINGON_EXIT, "CVTzActualisedRules::IsDaylightSavingOn Exit;dstOn=%u", dstOn ); |
|
1426 |
|
1401 return(dstOn); |
1427 return(dstOn); |
1402 } |
1428 } |
1403 |
1429 |
1404 /** |
1430 /** |
1405 Receives a time. Finds out which of these rules applies at the received time |
1431 Receives a time. Finds out which of these rules applies at the received time |
1415 |
1441 |
1416 @return TInt - offset from UTC (in minutes). |
1442 @return TInt - offset from UTC (in minutes). |
1417 */ |
1443 */ |
1418 EXPORT_C TInt CVTzActualisedRules::GetOffsetFromRuleL(const TTime& aUserTime, TTzTimeReference aUserTimeRef) const |
1444 EXPORT_C TInt CVTzActualisedRules::GetOffsetFromRuleL(const TTime& aUserTime, TTzTimeReference aUserTimeRef) const |
1419 { |
1445 { |
1446 OstTraceDefExt5(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CVTZACTUALISEDRULES_GETOFFSETFROMRULEL_ENTRY, "CVTzActualisedRules::GetOffsetFromRuleL Entry;aUserTime:Year=%d;Month=%d;Day=%d;Hour=%d;Min=%d", aUserTime.DateTime().Year(), aUserTime.DateTime().Month(), aUserTime.DateTime().Day(), aUserTime.DateTime().Hour(), aUserTime.DateTime().Minute()); |
|
1447 |
|
1420 // The first rule with iTimeOfChange <= aUserTime that is found going backwards in the array is the one that |
1448 // The first rule with iTimeOfChange <= aUserTime that is found going backwards in the array is the one that |
1421 // applies at the requested aUserTime. |
1449 // applies at the requested aUserTime. |
1422 __ASSERT_ALWAYS(aUserTimeRef!=ETzStdTimeReference, RTz::Panic(RTz::EPanicUnsupportedTimeReference)); |
1450 __ASSERT_ALWAYS(aUserTimeRef!=ETzStdTimeReference, RTz::Panic(RTz::EPanicUnsupportedTimeReference)); |
1423 |
1451 |
1424 // we traverse the array of rules, starting from the last one, until we find the |
1452 // we traverse the array of rules, starting from the last one, until we find the |
1470 } |
1498 } |
1471 } |
1499 } |
1472 |
1500 |
1473 if (!ruleFound) |
1501 if (!ruleFound) |
1474 { |
1502 { |
1503 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_ERROR, CVTZACTUALISEDRULES_GETOFFSETFROMRULEL, "CVTzActualisedRules::GetOffsetFromRuleL:Rule not found" ); |
|
1504 |
|
1475 User::Leave(KErrNotFound); |
1505 User::Leave(KErrNotFound); |
1476 } |
1506 } |
1507 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CVTZACTUALISEDRULES_GETOFFSETFROMRULEL_EXIT, "CVTzActualisedRules::GetOffsetFromRuleL Exit;resultOffset=%d", resultOffset ); |
|
1477 |
1508 |
1478 return resultOffset; |
1509 return resultOffset; |
1479 } |
1510 } |
1480 |
1511 |
1481 /** |
1512 /** |