calendarui/regionalplugins/calenregionalutil/src/calenlunarinfoprovider.cpp
branchRCL_3
changeset 66 bd7edf625bdd
parent 65 12af337248b1
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include "calendarui_debug.h"
    19 #include "calendarui_debug.h"
    20 #include "CalenLunarInfoProvider.h"
    20 #include "calenlunarinfoprovider.h"
    21 #include "CalenLunarInfo.h"
    21 #include "calenlunarinfo.h"
    22 #include "CalenSolarTerms.h"
    22 #include "calensolarterms.h"
    23 
    23 
    24 #include <calendarconverter.h>
    24 #include <calendarconverter.h>
    25 #include "OstTraceDefinitions.h"
       
    26 #ifdef OST_TRACE_COMPILER_IN_USE
       
    27 #include "calenlunarinfoproviderTraces.h"
       
    28 #endif
       
    29 
       
    30 
    25 
    31 
    26 
    32 // ---------------------------------------------------------
    27 // ---------------------------------------------------------
    33 // CCalenCalanderConverter::CalculateCelestialIndex
    28 // CCalenCalanderConverter::CalculateCelestialIndex
    34 // Calculates a Heavenly stem's index and a Terrestrial branch's index
    29 // Calculates a Heavenly stem's index and a Terrestrial branch's index
    36 //
    31 //
    37 static void CelestialIndex(const TChineseDate& aChineseDate,
    32 static void CelestialIndex(const TChineseDate& aChineseDate,
    38                            TInt& aCelestialIndex, 
    33                            TInt& aCelestialIndex, 
    39                            TInt& aTerrestrialIndex)
    34                            TInt& aTerrestrialIndex)
    40     {
    35     {
    41     OstTraceFunctionEntry0( _CELESTIALINDEX_ENTRY );
    36     TRACE_ENTRY_POINT;
       
    37     
    42     aCelestialIndex = aChineseDate.iYear % 10;
    38     aCelestialIndex = aChineseDate.iYear % 10;
    43     
    39     
    44     if (aCelestialIndex == 0)
    40     if (aCelestialIndex == 0)
    45         {
    41         {
    46         aCelestialIndex = 9;
    42         aCelestialIndex = 9;
    58     else
    54     else
    59         {
    55         {
    60         aTerrestrialIndex--;
    56         aTerrestrialIndex--;
    61         }
    57         }
    62     
    58     
    63     OstTraceFunctionExit0( _CELESTIALINDEX_EXIT );
    59     TRACE_EXIT_POINT;
    64     }
    60     }
    65 
    61 
    66 // -----------------------------------------------------------------------------
    62 // -----------------------------------------------------------------------------
    67 // CCalenCalanderConverter::ChineseFestival
    63 // CCalenCalanderConverter::ChineseFestival
    68 // -----------------------------------------------------------------------------
    64 // -----------------------------------------------------------------------------
    69 //
    65 //
    70 static TCalenLunarInfo::TFestival ChineseFestival(
    66 static TCalenLunarInfo::TFestival ChineseFestival(
    71     const TChineseDate& aChineseDate, 
    67     const TChineseDate& aChineseDate, 
    72     const TChineseDate& aNextDate)
    68     const TChineseDate& aNextDate)
    73     {
    69     {
    74     OstTraceFunctionEntry0( _CHINESEFESTIVAL_ENTRY );
    70     TRACE_ENTRY_POINT;
       
    71     
    75     TCalenLunarInfo::TFestival index = TCalenLunarInfo::ENoFestival;
    72     TCalenLunarInfo::TFestival index = TCalenLunarInfo::ENoFestival;
    76 
    73 
    77     if (!aChineseDate.iLeapMonth)
    74     if (!aChineseDate.iLeapMonth)
    78         {
    75         {
    79         if (aChineseDate.iMonth == 1 && aChineseDate.iDay == 1)
    76         if (aChineseDate.iMonth == 1 && aChineseDate.iDay == 1)
   117         aNextDate.iMonth == 1 && aNextDate.iDay == 1)
   114         aNextDate.iMonth == 1 && aNextDate.iDay == 1)
   118         {
   115         {
   119         index = TCalenLunarInfo::EFestivalNewYearEve;
   116         index = TCalenLunarInfo::EFestivalNewYearEve;
   120         }
   117         }
   121     
   118     
   122     OstTraceFunctionExit0( _CHINESEFESTIVAL_EXIT );
   119     TRACE_EXIT_POINT;
   123     return index;
   120     return index;
   124     }
   121     }
   125 
   122 
   126 // -----------------------------------------------------------------------------
   123 // -----------------------------------------------------------------------------
   127 // CCalenLunarInfoProvider::NewL
   124 // CCalenLunarInfoProvider::NewL
   128 // -----------------------------------------------------------------------------
   125 // -----------------------------------------------------------------------------
   129 //
   126 //
   130 EXPORT_C CCalenLunarInfoProvider* CCalenLunarInfoProvider::NewL(RFs& aFs)
   127 EXPORT_C CCalenLunarInfoProvider* CCalenLunarInfoProvider::NewL(RFs& aFs)
   131     {
   128     {
   132     OstTraceFunctionEntry0( CCALENLUNARINFOPROVIDER_NEWL_ENTRY );
   129     TRACE_ENTRY_POINT;
       
   130     
   133     CCalenLunarInfoProvider* self = new (ELeave) CCalenLunarInfoProvider();
   131     CCalenLunarInfoProvider* self = new (ELeave) CCalenLunarInfoProvider();
   134     CleanupStack::PushL(self);
   132     CleanupStack::PushL(self);
   135     self->ConstructL(aFs);
   133     self->ConstructL(aFs);
   136     CleanupStack::Pop(self);
   134     CleanupStack::Pop(self);
   137     
   135     
   138     OstTraceFunctionExit0( CCALENLUNARINFOPROVIDER_NEWL_EXIT );
   136     TRACE_EXIT_POINT;
   139     return self;
   137     return self;
   140     }
   138     }
   141 
   139 
   142 // -----------------------------------------------------------------------------
   140 // -----------------------------------------------------------------------------
   143 // CCalenLunarInfoProvider::~CCalenLunarInfoProvider
   141 // CCalenLunarInfoProvider::~CCalenLunarInfoProvider
   144 // -----------------------------------------------------------------------------
   142 // -----------------------------------------------------------------------------
   145 //
   143 //
   146 EXPORT_C CCalenLunarInfoProvider::~CCalenLunarInfoProvider()
   144 EXPORT_C CCalenLunarInfoProvider::~CCalenLunarInfoProvider()
   147     {
   145     {
   148     OstTraceFunctionEntry0( CCALENLUNARINFOPROVIDER_CCALENLUNARINFOPROVIDER_ENTRY );
   146     TRACE_ENTRY_POINT;
       
   147     
   149     delete iSolarTerms; 
   148     delete iSolarTerms; 
   150     delete iConverter;
   149     delete iConverter;
   151     OstTraceFunctionExit0( CCALENLUNARINFOPROVIDER_CCALENLUNARINFOPROVIDER_EXIT );
   150     
       
   151     TRACE_EXIT_POINT;
   152     }
   152     }
   153 
   153 
   154 // -----------------------------------------------------------------------------
   154 // -----------------------------------------------------------------------------
   155 // CCalenLunarInfoProvider::CCalenLunarInfoProvider
   155 // CCalenLunarInfoProvider::CCalenLunarInfoProvider
   156 // -----------------------------------------------------------------------------
   156 // -----------------------------------------------------------------------------
   157 //
   157 //
   158 CCalenLunarInfoProvider::CCalenLunarInfoProvider()
   158 CCalenLunarInfoProvider::CCalenLunarInfoProvider()
   159     {
   159     {
   160     OstTraceFunctionEntry0( DUP1_CCALENLUNARINFOPROVIDER_CCALENLUNARINFOPROVIDER_ENTRY );
   160     TRACE_ENTRY_POINT;
   161     OstTraceFunctionExit0( DUP1_CCALENLUNARINFOPROVIDER_CCALENLUNARINFOPROVIDER_EXIT );
   161     TRACE_EXIT_POINT;
   162     }
   162     }
   163 
   163 
   164 // -----------------------------------------------------------------------------
   164 // -----------------------------------------------------------------------------
   165 // CCalenLunarInfoProvider::ConstructL
   165 // CCalenLunarInfoProvider::ConstructL
   166 // -----------------------------------------------------------------------------
   166 // -----------------------------------------------------------------------------
   167 //
   167 //
   168 void CCalenLunarInfoProvider::ConstructL(RFs& aFs)
   168 void CCalenLunarInfoProvider::ConstructL(RFs& aFs)
   169     {
   169     {
   170 OstTraceFunctionEntry0( CCALENLUNARINFOPROVIDER_CONSTRUCTL_ENTRY );
   170     TRACE_ENTRY_POINT;
   171 
   171 
   172     iConverter = CChineseCalendarConverter::NewL();
   172     iConverter = CChineseCalendarConverter::NewL();
   173     iSolarTerms = CCalenSolarTerms::NewL(aFs);
   173     iSolarTerms = CCalenSolarTerms::NewL(aFs);
   174     OstTraceFunctionExit0( CCALENLUNARINFOPROVIDER_CONSTRUCTL_EXIT );
   174     
       
   175     TRACE_EXIT_POINT;
   175     }
   176     }
   176 
   177 
   177 // -----------------------------------------------------------------------------
   178 // -----------------------------------------------------------------------------
   178 // CCalenLunarInfoProvider::GetLunarInfoL
   179 // CCalenLunarInfoProvider::GetLunarInfoL
   179 // -----------------------------------------------------------------------------
   180 // -----------------------------------------------------------------------------
   180 //
   181 //
   181 EXPORT_C TCalenLunarInfo CCalenLunarInfoProvider::GetLunarInfoL( const TTime& aDay ) 
   182 EXPORT_C TCalenLunarInfo CCalenLunarInfoProvider::GetLunarInfoL( const TTime& aDay ) 
   182     {
   183     {
   183     OstTraceFunctionEntry0( CCALENLUNARINFOPROVIDER_GETLUNARINFOL_ENTRY );
   184     TRACE_ENTRY_POINT;
       
   185        
   184     TDateTime dayDt = aDay.DateTime();
   186     TDateTime dayDt = aDay.DateTime();
   185 
   187 
   186     TTime nextDay = aDay + TTimeIntervalDays(1);
   188     TTime nextDay = aDay + TTimeIntervalDays(1);
   187     TDateTime nextDayDt = nextDay.DateTime();
   189     TDateTime nextDayDt = nextDay.DateTime();
   188 
   190 
   197     info.iGregorianDate = aDay;
   199     info.iGregorianDate = aDay;
   198     info.iFestival = ChineseFestival( chineseDate, nextChineseDate );
   200     info.iFestival = ChineseFestival( chineseDate, nextChineseDate );
   199     info.iSolarTerm = iSolarTerms->CheckSolarTermDateL( dayDt );
   201     info.iSolarTerm = iSolarTerms->CheckSolarTermDateL( dayDt );
   200     CelestialIndex( chineseDate, info.iHeavenlyStem, info.iTerrestialBranch );
   202     CelestialIndex( chineseDate, info.iHeavenlyStem, info.iTerrestialBranch );
   201     
   203     
   202     OstTraceFunctionExit0( CCALENLUNARINFOPROVIDER_GETLUNARINFOL_EXIT );
   204     TRACE_EXIT_POINT;
   203     return info;
   205     return info;
   204     }
   206     }