pimappsupport/chinesecalendaralg/originalsrc/ArithmeticalCal.cpp
branchRCL_3
changeset 12 38571fd2a704
equal deleted inserted replaced
5:42814f902fe6 12:38571fd2a704
       
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implementation of the TArithmeticalCalendar class.
       
    15 // 
       
    16 //
       
    17 
       
    18 // System includes
       
    19 #include <e32math.h>
       
    20 
       
    21 // User includes
       
    22 #include "calconvArithmeticalCal.h"
       
    23 
       
    24 
       
    25 //
       
    26 // Construction/Destruction
       
    27 //
       
    28 
       
    29 //------------------------------------------------------
       
    30 // Class:       TArithmeticalCalendar
       
    31 // Function:    TArithmeticalCalendar
       
    32 // Arguments:   None
       
    33 //
       
    34 // Comments:    Constructor
       
    35 //
       
    36 // Return:      None
       
    37 //------------------------------------------------------
       
    38 TArithmeticalCalendar::TArithmeticalCalendar()
       
    39 	{
       
    40 	}
       
    41 
       
    42 //------------------------------------------------------
       
    43 // Class:       TArithmeticalCalendar
       
    44 // Function:    DaysMonthsElapsed
       
    45 // Arguments:   const TInt ,const TInt ,const TInt , const TInt ,const TInt
       
    46 //
       
    47 // Comments:    The use of this function varies between calendars 
       
    48 //				however since the form of the equation is the same it 
       
    49 //				is represented in this class.  The equation is use to 
       
    50 //				calculate the number of days in whole months of a particular
       
    51 //				year up to a particular date in the Gregorian and 
       
    52 //				Islamic calendars.  The Hebrew calendar uses this
       
    53 //				equation to calculate the number of whole months 
       
    54 //				since the start of the calendar.
       
    55 //				
       
    56 //
       
    57 // Return:      See comments
       
    58 //------------------------------------------------------
       
    59 TInt TArithmeticalCalendar::DaysMonthsElapsed(const TInt aYear) const
       
    60 	{
       
    61 	TReal tempReal;
       
    62 	TInt result;
       
    63 
       
    64 	tempReal = iOffset * iLeaps;
       
    65 	Mod(tempReal,tempReal,iCycle);
       
    66 	tempReal = ((iLeaps * aYear) - iLeaps + tempReal) / iCycle;
       
    67 	Floor(result,tempReal);
       
    68 	result = result + (iStdYearMonth * (aYear - KCalConvYearOffsetByOne));
       
    69 
       
    70 	return result;
       
    71 	}
       
    72 
       
    73 //------------------------------------------------------
       
    74 // Class:       TArithmeticalCalendar
       
    75 // Function:    IsLeapYear
       
    76 // Arguments:   const TInt , const TInt ,const TInt , const TInt
       
    77 //
       
    78 // Comments:    Determines whether the given year is a leap year.
       
    79 //				Gregorian uses a different implimentation.
       
    80 //
       
    81 // Return:      ETrue if leap year, else EFalse
       
    82 //------------------------------------------------------
       
    83 TBool TArithmeticalCalendar::IsLeapYear(const TInt aYear) const
       
    84 	{
       
    85 	TReal result;
       
    86 	TBool rtn;
       
    87 
       
    88 	result = (aYear + iOffset) * iLeaps;
       
    89 	Mod(result,result,iCycle);
       
    90 
       
    91 	if(result < iLeaps)
       
    92 		{
       
    93 		rtn = ETrue;
       
    94 		}
       
    95 	else
       
    96 		{
       
    97 		rtn = EFalse;
       
    98 		}
       
    99 
       
   100 	return rtn;
       
   101 	}
       
   102 
       
   103 //------------------------------------------------------
       
   104 // Class:       TArithmeticalCalendar
       
   105 // Function:    DayMonthInYear
       
   106 // Arguments:   None
       
   107 //
       
   108 // Comments:    This function Determines the month based on
       
   109 //				the number of days into the year it is
       
   110 //
       
   111 // Return:      TInt - Month
       
   112 //------------------------------------------------------
       
   113 TInt TArithmeticalCalendar::DayMonthInYear(const TInt aDays) const
       
   114 	{
       
   115 	TReal tempReal;
       
   116 	TInt result;
       
   117 
       
   118 	tempReal = iLeaps * iOffset;
       
   119 	Mod(tempReal,tempReal,iCycle);
       
   120 	tempReal = (iCycle * aDays) + (iCycle * iStdYearMonth) + iLeaps - KCalConvYearOffsetByOne + iCycle - tempReal;
       
   121 	tempReal = tempReal / ((iCycle * iStdYearMonth) + iLeaps);
       
   122 	Floor(result,tempReal);
       
   123 
       
   124 	return result;
       
   125 	}