00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <e32std.h>
00033 #include <e32base.h>
00034 #include <e32cons.h>
00035 #include <calendarconverter.h>
00036 #include <ecom/ecom.h>
00037
00038
00039
00040 static CConsoleBase* console;
00041
00042
00043 static CChineseCalendarConverter* gCalendarConverter;
00044
00045
00046 _LIT(KMsgPressAnyKey,"\nPress any key to continue\n\n");
00047 _LIT(KConsoleStars,"\n*************************\n");
00048
00049 static void PrintChineseDate(TChineseDate aDate);
00050 static void PrintGregorianDate(TDateTime aDate);
00051
00052
00053 static TChineseDate& GregorianDatesToLunarDatesL(TDateTime aStartDT)
00054 {
00055 _LIT(KConsoleMessage,"This function demonstrates conversion of Gregorian to Chinese dates\n");
00056 console->Printf(KConsoleMessage);
00057
00058 _LIT(KConsoleMessage1,"\nBefore conversion, the date in Gregorian format is: ");
00059 console->Printf(KConsoleMessage1);
00060 PrintGregorianDate(aStartDT);
00061
00062 TInt err1;
00063 static TChineseDate chineseDate;
00064
00065 TRAP(err1,gCalendarConverter->DateTimeToChineseL(aStartDT,chineseDate));
00066 if (err1)
00067 {
00068 _LIT(KConsoleMessage2,"Conversion error");
00069 console->Printf(KConsoleMessage2);
00070 }
00071 else
00072 {
00073 _LIT(KConsoleMessage3,"\nAfter conversion, the date in Chinese format is:\n");
00074 console->Printf(KConsoleMessage3);
00075 PrintChineseDate(chineseDate);
00076 }
00077 console->Printf(KConsoleStars);
00078
00079 console->Printf(KMsgPressAnyKey);
00080 console->Getch();
00081 return chineseDate;
00082 }
00083
00084
00085 static void LunarDatesToGregorianDatesL(TChineseDate aChineseDate)
00086 {
00087 _LIT(KConsoleMessage,"This function demonstrates conversion of Chinese to Gregorian dates\n");
00088 console->Printf(KConsoleMessage);
00089
00090 TDateTime dateTime;
00091
00092 _LIT(KConsoleMessage1,"\nBefore conversion, the date in Chinese format is:\n");
00093 console->Printf(KConsoleMessage1);
00094 PrintChineseDate(aChineseDate);
00095
00096 TInt err;
00097
00098 TRAP(err,gCalendarConverter->ChineseToDateTimeL(aChineseDate, dateTime));
00099 if (err)
00100 {
00101 _LIT(KConsoleMessage2,"Conversion error");
00102 console->Printf(KConsoleMessage2);
00103 }
00104 else
00105 {
00106 _LIT(KConsoleMessage3,"\nAfter conversion, the date is: ");
00107 console->Printf(KConsoleMessage3);
00108
00109 PrintGregorianDate(dateTime);
00110 console->Printf(KConsoleStars);
00111
00112 }
00113 }
00114
00115
00116 static void PrintChineseDate(TChineseDate aDate)
00117 {
00118 TBuf16<32> buffer;
00119 _LIT(KFormatTxt,"Cycle: %d \n");
00120 buffer.Format(KFormatTxt,aDate.iCycle);
00121 console->Printf(buffer);
00122
00123 _LIT(KFormatTxt2,"Year: %d \n");
00124 buffer.Format(KFormatTxt2,aDate.iYear);
00125 console->Printf(buffer);
00126
00127 _LIT(KFormatTxt3,"Month: %d \n");
00128 buffer.Format(KFormatTxt3,aDate.iMonth);
00129 console->Printf(buffer);
00130
00131 _LIT(KFormatTxt4,"LeapMonth: %d \n");
00132 buffer.Format(KFormatTxt4,aDate.iLeapMonth);
00133 console->Printf(buffer);
00134
00135 _LIT(KFormatTxt5,"Day: %d \n");
00136 buffer.Format(KFormatTxt5,aDate.iDay);
00137 console->Printf(buffer);
00138 }
00139
00140
00141 static void PrintGregorianDate(TDateTime aDate)
00142 {
00143 TBuf16<32> buffer;
00144 _LIT(KFormatTxt,"%d%S %S %d\n");
00145 TDateSuffix iDateSuffix = TDateSuffix(aDate.Day());
00146 TMonthName iMonthName = TMonthName(aDate.Month());
00147 buffer.Format(KFormatTxt,aDate.Day()+1,&iDateSuffix,&iMonthName,aDate.Year());
00148 console->Printf(buffer);
00149 }
00150
00151 static void EgCalconL()
00152 {
00153 gCalendarConverter = CChineseCalendarConverter::NewL();
00154 CleanupStack::PushL(gCalendarConverter);
00155
00156 TDateTime startDT;
00157 TDateTime finishDT;
00158
00159 gCalendarConverter->DateRange(startDT, finishDT);
00160
00161 TChineseDate chineseDate = GregorianDatesToLunarDatesL(startDT);
00162 LunarDatesToGregorianDatesL(chineseDate);
00163
00164 CleanupStack::PopAndDestroy(gCalendarConverter);
00165 REComSession::FinalClose();
00166 }
00167
00168 static void DoExampleL()
00169 {
00170
00171
00172 _LIT(KConsoleMessageDisplay, "Calcon Example");
00173 console = Console::NewL(KConsoleMessageDisplay,TSize(KConsFullScreen,KConsFullScreen));
00174 CleanupStack::PushL(console);
00175 console->Printf(KConsoleMessageDisplay);
00176 console->Printf(KConsoleStars);
00177
00178 TRAPD(err,EgCalconL());
00179
00180 if (err)
00181 {
00182 _LIT(KFailed,"\n\nExample failed: leave code=%d");
00183 console->Printf(KFailed, err);
00184 }
00185
00186
00187 console->Printf(KMsgPressAnyKey);
00188 console->Getch();
00189 CleanupStack::PopAndDestroy(console);
00190 }
00191
00192
00193 TInt E32Main()
00194 {
00195 __UHEAP_MARK;
00196
00197 CActiveScheduler* scheduler=new CActiveScheduler;
00198
00199 if (scheduler)
00200 {
00201 CActiveScheduler::Install(scheduler);
00202
00203 CTrapCleanup* cleanup=CTrapCleanup::New();
00204 if (cleanup)
00205 {
00206
00207 TRAP_IGNORE(DoExampleL());
00208 delete cleanup;
00209 }
00210 delete scheduler;
00211 }
00212 __UHEAP_MARKEND;
00213 return KErrNone;
00214 }
00215
00216
00217