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