|
1 /* |
|
2 * Copyright (c) 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 "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: Calendar Lunar Plugin |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "calendarui_debug.h" |
|
20 #include "calenlunarinfoprovider.h" |
|
21 #include "calenlunarinfo.h" |
|
22 #include "calensolarterms.h" |
|
23 |
|
24 #include <calendarconverter.h> |
|
25 |
|
26 |
|
27 // --------------------------------------------------------- |
|
28 // CCalenCalanderConverter::CalculateCelestialIndex |
|
29 // Calculates a Heavenly stem's index and a Terrestrial branch's index |
|
30 // --------------------------------------------------------- |
|
31 // |
|
32 static void CelestialIndex(const TChineseDate& aChineseDate, |
|
33 TInt& aCelestialIndex, |
|
34 TInt& aTerrestrialIndex) |
|
35 { |
|
36 TRACE_ENTRY_POINT; |
|
37 |
|
38 aCelestialIndex = aChineseDate.iYear % 10; |
|
39 |
|
40 if (aCelestialIndex == 0) |
|
41 { |
|
42 aCelestialIndex = 9; |
|
43 } |
|
44 else |
|
45 { |
|
46 aCelestialIndex--; |
|
47 } |
|
48 |
|
49 aTerrestrialIndex = aChineseDate.iYear % 12; |
|
50 if (aTerrestrialIndex == 0) |
|
51 { |
|
52 aTerrestrialIndex = 11; |
|
53 } |
|
54 else |
|
55 { |
|
56 aTerrestrialIndex--; |
|
57 } |
|
58 |
|
59 TRACE_EXIT_POINT; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CCalenCalanderConverter::ChineseFestival |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 static TCalenLunarInfo::TFestival ChineseFestival( |
|
67 const TChineseDate& aChineseDate, |
|
68 const TChineseDate& aNextDate) |
|
69 { |
|
70 TRACE_ENTRY_POINT; |
|
71 |
|
72 TCalenLunarInfo::TFestival index = TCalenLunarInfo::ENoFestival; |
|
73 |
|
74 if (!aChineseDate.iLeapMonth) |
|
75 { |
|
76 if (aChineseDate.iMonth == 1 && aChineseDate.iDay == 1) |
|
77 { |
|
78 index = TCalenLunarInfo::EFestivalSpring; |
|
79 } |
|
80 else if (aChineseDate.iMonth == 1 && aChineseDate.iDay == 15) |
|
81 { |
|
82 index = TCalenLunarInfo::EFestivalLantern; |
|
83 } |
|
84 else if (aChineseDate.iMonth == 5 && aChineseDate.iDay == 5) |
|
85 { |
|
86 index = TCalenLunarInfo::EFestivalDragonBoat; |
|
87 } |
|
88 else if (aChineseDate.iMonth == 7 && aChineseDate.iDay == 7) |
|
89 { |
|
90 index = TCalenLunarInfo::EFestivalSeventhNight; |
|
91 } |
|
92 else if (aChineseDate.iMonth == 7 && aChineseDate.iDay == 15) |
|
93 { |
|
94 index = TCalenLunarInfo::EFestivalGhost; |
|
95 } |
|
96 else if (aChineseDate.iMonth == 8 && aChineseDate.iDay == 15) |
|
97 { |
|
98 index = TCalenLunarInfo::EFestivalMidAutumn; |
|
99 } |
|
100 else if (aChineseDate.iMonth == 9 && aChineseDate.iDay == 9) |
|
101 { |
|
102 index = TCalenLunarInfo::EFestivalDoubleNinth; |
|
103 } |
|
104 else if (aChineseDate.iMonth == 12 && aChineseDate.iDay == 8) |
|
105 { |
|
106 index = TCalenLunarInfo::EFestivalTwelfthMonth; |
|
107 } |
|
108 else |
|
109 { |
|
110 // nothing |
|
111 } |
|
112 } |
|
113 if (!aNextDate.iLeapMonth && |
|
114 aNextDate.iMonth == 1 && aNextDate.iDay == 1) |
|
115 { |
|
116 index = TCalenLunarInfo::EFestivalNewYearEve; |
|
117 } |
|
118 |
|
119 TRACE_EXIT_POINT; |
|
120 return index; |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CCalenLunarInfoProvider::NewL |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 EXPORT_C CCalenLunarInfoProvider* CCalenLunarInfoProvider::NewL(RFs& aFs) |
|
128 { |
|
129 TRACE_ENTRY_POINT; |
|
130 |
|
131 CCalenLunarInfoProvider* self = new (ELeave) CCalenLunarInfoProvider(); |
|
132 CleanupStack::PushL(self); |
|
133 self->ConstructL(aFs); |
|
134 CleanupStack::Pop(self); |
|
135 |
|
136 TRACE_EXIT_POINT; |
|
137 return self; |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CCalenLunarInfoProvider::~CCalenLunarInfoProvider |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 EXPORT_C CCalenLunarInfoProvider::~CCalenLunarInfoProvider() |
|
145 { |
|
146 TRACE_ENTRY_POINT; |
|
147 |
|
148 delete iSolarTerms; |
|
149 delete iConverter; |
|
150 |
|
151 TRACE_EXIT_POINT; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CCalenLunarInfoProvider::CCalenLunarInfoProvider |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 CCalenLunarInfoProvider::CCalenLunarInfoProvider() |
|
159 { |
|
160 TRACE_ENTRY_POINT; |
|
161 TRACE_EXIT_POINT; |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CCalenLunarInfoProvider::ConstructL |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CCalenLunarInfoProvider::ConstructL(RFs& aFs) |
|
169 { |
|
170 TRACE_ENTRY_POINT; |
|
171 |
|
172 iConverter = CChineseCalendarConverter::NewL(); |
|
173 iSolarTerms = CCalenSolarTerms::NewL(aFs); |
|
174 |
|
175 TRACE_EXIT_POINT; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CCalenLunarInfoProvider::GetLunarInfoL |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 EXPORT_C TCalenLunarInfo CCalenLunarInfoProvider::GetLunarInfoL( const TTime& aDay ) |
|
183 { |
|
184 TRACE_ENTRY_POINT; |
|
185 |
|
186 TDateTime dayDt = aDay.DateTime(); |
|
187 |
|
188 TTime nextDay = aDay + TTimeIntervalDays(1); |
|
189 TDateTime nextDayDt = nextDay.DateTime(); |
|
190 |
|
191 TChineseDate chineseDate; |
|
192 TChineseDate nextChineseDate; |
|
193 |
|
194 iConverter->DateTimeToChineseL(dayDt, chineseDate); |
|
195 iConverter->DateTimeToChineseL(nextDayDt, nextChineseDate); |
|
196 |
|
197 TCalenLunarInfo info; |
|
198 info.iLunarDate = chineseDate; |
|
199 info.iGregorianDate = aDay; |
|
200 info.iFestival = ChineseFestival( chineseDate, nextChineseDate ); |
|
201 info.iSolarTerm = iSolarTerms->CheckSolarTermDateL( dayDt ); |
|
202 CelestialIndex( chineseDate, info.iHeavenlyStem, info.iTerrestialBranch ); |
|
203 |
|
204 TRACE_EXIT_POINT; |
|
205 return info; |
|
206 } |