1 /* |
|
2 * Copyright (c) 2002-2004 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 : Class looking after alarm fields for forms. |
|
15 * |
|
16 */ |
|
17 |
|
18 //debug |
|
19 #include "calendarui_debug.h" |
|
20 |
|
21 //user includes |
|
22 #include "CalenLunarInfoProvider.h" |
|
23 #include "CalenLunarInfo.h" |
|
24 #include "CalenSolarTerms.h" |
|
25 #include <calendarconverter.h> |
|
26 #include "CalenKoreanLunarPlugin.h" |
|
27 #include "KoreanCalConv.h" |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KDaysInJanuary = 31; // total day count of January |
|
31 const TInt KDaysInMarch = 31; // total day count of January |
|
32 const TInt KDaysInDecemberAfterWinterSolstice = 10; // day count of December starting from winter solstice (21.12) |
|
33 const TInt K105thDayAfterWinterSolstice = 105; |
|
34 |
|
35 // ======== MEMBER FUNCTIONS ======== |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // TCalenLunarInfo::TLunarFestival() |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 static TCalenLunarInfo::TLunarFestival KoreanLunarFestival( |
|
43 const TKoreanDate& aDate, |
|
44 const TKoreanDate& aNextDate, |
|
45 const TTime& aDay ) |
|
46 { |
|
47 TRACE_ENTRY_POINT; |
|
48 |
|
49 TCalenLunarInfo::TLunarFestival index = TCalenLunarInfo::ENoFestival; |
|
50 |
|
51 if (!aDate.iLeapMonth) |
|
52 { |
|
53 if (aDate.iMonth == 4 && aDate.iDay == 8) |
|
54 { |
|
55 index = TCalenLunarInfo::EFestivalBuddhaBirthDay; |
|
56 } |
|
57 else if (aDate.iMonth == 8 && aDate.iDay == 15) |
|
58 { |
|
59 index = TCalenLunarInfo::EFestivalHarvest; |
|
60 } |
|
61 else if(aDate.iMonth == 1 && aDate.iDay == 15) |
|
62 { |
|
63 // full moon day |
|
64 index = TCalenLunarInfo::EFestivalFullMoonDay; |
|
65 } |
|
66 else if(aDate.iMonth == 3 && aDate.iDay == 3) |
|
67 { |
|
68 // 3rd of March festival |
|
69 index = TCalenLunarInfo::EFestival3rdMarchDay; |
|
70 } |
|
71 else if(aDate.iMonth == 5 && aDate.iDay == 5) |
|
72 { |
|
73 // dano festival |
|
74 index = TCalenLunarInfo::EFestivalDano; |
|
75 } |
|
76 else if(aDate.iMonth == 6 && aDate.iDay == 15) |
|
77 { |
|
78 // ?? festival |
|
79 index = TCalenLunarInfo::EFestivalUnknown_1; |
|
80 } |
|
81 else if(aDate.iMonth == 7 && aDate.iDay == 7) |
|
82 { |
|
83 // 7th of July festival |
|
84 index = TCalenLunarInfo::EFestival7thJulyDay; |
|
85 } |
|
86 else if(aDate.iMonth == 7 && aDate.iDay == 15) |
|
87 { |
|
88 // ?? festival |
|
89 index = TCalenLunarInfo::EFestivalUnknown_2; |
|
90 } |
|
91 else if(aDate.iMonth == 9 && aDate.iDay == 9) |
|
92 { |
|
93 // ?? festival |
|
94 index = TCalenLunarInfo::EFestivalUnknown_3; |
|
95 } |
|
96 else |
|
97 { |
|
98 TDateTime date = aDay.DateTime(); |
|
99 TMonth month = date.Month(); |
|
100 TInt day = date.Day(); |
|
101 TInt year = date.Year(); |
|
102 |
|
103 if( month == EApril ) |
|
104 { |
|
105 // Check if it's 105th hay after Dong Shi (winter solstice) |
|
106 TInt daysInFebruary; |
|
107 if(year%4 == 0) |
|
108 { |
|
109 // leap year |
|
110 daysInFebruary = 29; |
|
111 } |
|
112 else |
|
113 { |
|
114 daysInFebruary = 28; |
|
115 } |
|
116 |
|
117 // we need to count dates beginning from winter soltice (21.22) till end of march |
|
118 TInt daysBeforeApril = |
|
119 KDaysInDecemberAfterWinterSolstice + KDaysInJanuary + daysInFebruary + KDaysInMarch; |
|
120 |
|
121 if( daysBeforeApril + day == K105thDayAfterWinterSolstice ) |
|
122 { |
|
123 index = TCalenLunarInfo::EFestival105thDayAfterWS; |
|
124 } |
|
125 } |
|
126 } |
|
127 } |
|
128 if (!aNextDate.iLeapMonth && |
|
129 aDate.iMonth == 1 && aDate.iDay == 1) |
|
130 { |
|
131 index = TCalenLunarInfo::EFestivalNewYearDay; |
|
132 } |
|
133 |
|
134 TRACE_EXIT_POINT; |
|
135 return index; |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // TCalenLunarInfo::TSolarFestival() |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 static TCalenLunarInfo::TSolarFestival KoreanSolarFestival( |
|
143 const TTime& aDay ) |
|
144 { |
|
145 TRACE_ENTRY_POINT; |
|
146 |
|
147 TCalenLunarInfo::TSolarFestival index = TCalenLunarInfo::ENoSolarFestival; |
|
148 |
|
149 TDateTime date = aDay.DateTime(); |
|
150 TMonth month = date.Month(); |
|
151 TInt day = date.Day(); |
|
152 |
|
153 if( month == EJanuary && day == 0 ) |
|
154 { |
|
155 index = TCalenLunarInfo::ESolarFestivalNewYearDay; |
|
156 } |
|
157 else if( month == EMarch && day == 0 ) |
|
158 { |
|
159 index = TCalenLunarInfo::ESolarFestivalIndependenceMovement; |
|
160 } |
|
161 else if( month == EMay && day == 4 ) |
|
162 { |
|
163 index = TCalenLunarInfo::ESolarFestivalChildrensDay; |
|
164 } |
|
165 else if( month == EJune && day == 5 ) |
|
166 { |
|
167 index = TCalenLunarInfo::ESolarFestivalMemorialDay; |
|
168 } |
|
169 else if( month == EJuly && day == 16 ) |
|
170 { |
|
171 index = TCalenLunarInfo::ESolarFestivalConstitutionDay; |
|
172 } |
|
173 else if( month == EAugust && day == 14 ) |
|
174 { |
|
175 index = TCalenLunarInfo::ESolarFestivalLiberationDay; |
|
176 } |
|
177 else if( month == EOctober && day == 2 ) |
|
178 { |
|
179 index = TCalenLunarInfo::ESolarFestivalFoundationDay; |
|
180 } |
|
181 else if( month == EDecember && day == 24 ) |
|
182 { |
|
183 index = TCalenLunarInfo::ESolarFestivalChristmasDay; |
|
184 } |
|
185 else if( month == EOctober && day == 8 ) |
|
186 { |
|
187 index = TCalenLunarInfo::ESolarFestivalHangulDay; |
|
188 } |
|
189 TRACE_EXIT_POINT; |
|
190 return index; |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // CCalenLunarInfoProvider::NewL() |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 CCalenLunarInfoProvider* CCalenLunarInfoProvider::NewL( RFs& aFs ) |
|
198 { |
|
199 TRACE_ENTRY_POINT; |
|
200 |
|
201 CCalenLunarInfoProvider* self = new (ELeave) CCalenLunarInfoProvider(); |
|
202 CleanupStack::PushL(self); |
|
203 self->ConstructL(aFs); |
|
204 CleanupStack::Pop(self); |
|
205 |
|
206 TRACE_EXIT_POINT; |
|
207 return self; |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // CCalenLunarInfoProvider::~CCalenLunarInfoProvider() |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 CCalenLunarInfoProvider::~CCalenLunarInfoProvider() |
|
215 { |
|
216 TRACE_ENTRY_POINT; |
|
217 |
|
218 delete iSolarTerms; |
|
219 delete iConverter; |
|
220 |
|
221 TRACE_EXIT_POINT; |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CCalenLunarInfoProvider::CCalenLunarInfoProvider() |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 CCalenLunarInfoProvider::CCalenLunarInfoProvider() |
|
229 { |
|
230 TRACE_ENTRY_POINT; |
|
231 TRACE_EXIT_POINT; |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // CCalenLunarInfoProvider::ConstructL() |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 void CCalenLunarInfoProvider::ConstructL( RFs& aFs ) |
|
239 { |
|
240 TRACE_ENTRY_POINT; |
|
241 |
|
242 iConverter = CKoreanCalConv::NewL(); |
|
243 iSolarTerms = CCalenSolarTerms::NewL( aFs ); |
|
244 |
|
245 TRACE_EXIT_POINT; |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // CCalenLunarInfoProvider::GetLunarInfoL() |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 TCalenLunarInfo CCalenLunarInfoProvider::GetLunarInfoL( const TTime& aDay ) |
|
253 { |
|
254 TRACE_ENTRY_POINT; |
|
255 |
|
256 TDateTime dayDt = aDay.DateTime(); |
|
257 |
|
258 TTime nextDay = aDay + TTimeIntervalDays(1); |
|
259 TDateTime nextDayDt = nextDay.DateTime(); |
|
260 |
|
261 TKoreanDate koreanDate; |
|
262 TKoreanDate nextKoreanDate; |
|
263 |
|
264 iConverter->DateTimeToKoreanL(dayDt, koreanDate); |
|
265 iConverter->DateTimeToKoreanL(nextDayDt, nextKoreanDate); |
|
266 |
|
267 |
|
268 TCalenLunarInfo info; |
|
269 info.iLunarDate = koreanDate; |
|
270 info.iGregorianDate = aDay; |
|
271 info.iLunarFestival = KoreanLunarFestival( koreanDate, nextKoreanDate, aDay); |
|
272 info.iSolarFestival = KoreanSolarFestival( aDay ); |
|
273 info.iSolarTerm = iSolarTerms->CheckSolarTermDateL( dayDt ); |
|
274 |
|
275 TRACE_EXIT_POINT; |
|
276 return info; |
|
277 } |
|
278 |
|
279 // End of file |
|