pimappsupport/chinesecalendaralg/pluginsrc/calendar.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 TCalendar class.
       
    15 //
       
    16 
       
    17 #include <e32def.h>
       
    18 #include <e32math.h>
       
    19 #include "calendar.h"
       
    20 
       
    21 // Constants
       
    22 const TReal KRemainderApproxZero = 0.000000001;
       
    23 
       
    24 //////////////////////////////////////////////////////////////////////
       
    25 // Construction/Destruction
       
    26 //////////////////////////////////////////////////////////////////////
       
    27 
       
    28 //------------------------------------------------------
       
    29 // Class:       TCalendar
       
    30 // Function:    TCalendar
       
    31 // Arguments:   None
       
    32 //
       
    33 // Comments:    Constructor
       
    34 //
       
    35 // Return:      none
       
    36 //------------------------------------------------------
       
    37 TCalendar::TCalendar()
       
    38 	{
       
    39 	iJulianDay = 0;
       
    40 	}
       
    41 
       
    42 
       
    43 //------------------------------------------------------
       
    44 // Class:       TCalendar
       
    45 // Function:    operator =
       
    46 // Arguments:   TCalendar &TCal  -  the TCalendar
       
    47 //				class by referance.
       
    48 //
       
    49 // Comments:    Copies the JulianDay value from one instance 
       
    50 //				of TCalendar to an other.
       
    51 //
       
    52 // Return:      *this
       
    53 //------------------------------------------------------
       
    54 TCalendar& TCalendar::operator =(const TCalendar &TCal)
       
    55 	{
       
    56 	iJulianDay = TCal.iJulianDay;
       
    57 	return (*this);
       
    58 	}
       
    59 
       
    60 //------------------------------------------------------
       
    61 // Class:       TCalendar
       
    62 // Function:    Floor
       
    63 // Arguments:   TReal& ,TReal& 
       
    64 //
       
    65 // Comments:    This function returns the floor value of the
       
    66 //				value given in the aNum argument as Determined by:
       
    67 //
       
    68 //				the largest integer less than or equal to aNum
       
    69 //
       
    70 // Return:      None
       
    71 //------------------------------------------------------
       
    72 void TCalendar::Floor(TInt& aRes,const TReal& aNum) const
       
    73 	{
       
    74 	TReal tempReal;
       
    75 	TInt32 tempReal32;
       
    76 	TInt precision = 0;
       
    77 
       
    78 	TReal wholeNoTemp;
       
    79 	Math::Frac(wholeNoTemp,aNum);
       
    80 	if(wholeNoTemp < 0)
       
    81 		{
       
    82 		wholeNoTemp = -wholeNoTemp;
       
    83 		}
       
    84 
       
    85 	if((aNum == 0) || (wholeNoTemp < KRemainderApproxZero))
       
    86 		{
       
    87 		tempReal = aNum;
       
    88 		}
       
    89 	else
       
    90 		{
       
    91 		tempReal = aNum - KCalConvPointFive;
       
    92 		}
       
    93 	Math::Round(tempReal,tempReal,precision);
       
    94 	Math::Int(tempReal32,tempReal);
       
    95 	aRes = tempReal32;
       
    96 	}
       
    97 
       
    98 //------------------------------------------------------
       
    99 // Class:       TCalendar
       
   100 // Function:    Ceiling
       
   101 // Arguments:   TReal& ,TReal& 
       
   102 //
       
   103 // Comments:    This function returns the ceiling value of the
       
   104 //				value given in the aNum argument as Determined by:
       
   105 //
       
   106 //				the smallest integer less than or equal to aNum
       
   107 //
       
   108 // Return:      None
       
   109 //------------------------------------------------------
       
   110 void TCalendar::Ceiling(TInt& aRes,const TReal& aNum) const
       
   111 	{
       
   112 	TReal tempReal;
       
   113 	TInt32 tempReal32;
       
   114 	TInt precision = 0;
       
   115 
       
   116 	TReal wholeNoTemp;
       
   117 	Math::Frac(wholeNoTemp,aNum);
       
   118 	if(wholeNoTemp < 0)
       
   119 		{
       
   120 		wholeNoTemp = -wholeNoTemp;
       
   121 		}
       
   122 
       
   123 	if((aNum == 0) || (wholeNoTemp < KRemainderApproxZero))
       
   124 		{
       
   125 		tempReal = aNum;
       
   126 		}
       
   127 	else
       
   128 		{
       
   129 		tempReal = aNum + KCalConvPointFive;
       
   130 		}
       
   131 	Math::Round(tempReal,tempReal,precision);
       
   132 	Math::Int(tempReal32,tempReal);
       
   133 	aRes = tempReal32;
       
   134 	}
       
   135 
       
   136 //------------------------------------------------------
       
   137 // Class:       TCalendar
       
   138 // Function:    Mod
       
   139 // Arguments:   TReal &, const TReal &, const TReal &
       
   140 //
       
   141 // Comments:    return the mod of the aAbscissa / aDenominator
       
   142 //				quotient as Determined by:
       
   143 //				
       
   144 //				aAbscissa - aDenominator(floor(aAbscissa / aDenominator))
       
   145 //
       
   146 // Return:      None
       
   147 //------------------------------------------------------
       
   148 void TCalendar::Mod(TReal &aRes, const TReal &aAbscissa, const TReal &aDenominator) const
       
   149 	{
       
   150 	TReal quo;
       
   151 	TInt tempInt;
       
   152 
       
   153 	quo = aAbscissa / aDenominator;
       
   154 
       
   155 	Floor(tempInt,quo);
       
   156 
       
   157 	aRes = aAbscissa - (aDenominator * tempInt);
       
   158 	}
       
   159 
       
   160 //------------------------------------------------------
       
   161 // Class:       TCalendar
       
   162 // Function:    Amod
       
   163 // Arguments:   TReal &, const TReal &, const TReal &
       
   164 //
       
   165 // Comments:    Determines the adjusted remainder
       
   166 //
       
   167 // Return:      None
       
   168 //------------------------------------------------------
       
   169 void TCalendar::Amod(TReal &aRes, const TReal &aAbscissa, const TReal &aDenominator) const
       
   170 	{
       
   171 	Mod(aRes,aAbscissa,aDenominator);
       
   172 
       
   173 	if(aRes == 0)
       
   174 		{
       
   175 		aRes = aDenominator;
       
   176 		}
       
   177 	}
       
   178 
       
   179 //------------------------------------------------------
       
   180 // Class:       TCalendar
       
   181 // Function:    Round
       
   182 // Arguments:   TInt &, TReal &
       
   183 //
       
   184 // Comments:    rounds of the aNum argument
       
   185 //
       
   186 // Return:      None
       
   187 //------------------------------------------------------
       
   188 void TCalendar::Round(TInt &aRes, TReal &aNum) const
       
   189 	{
       
   190 	TReal temp;
       
   191 	temp = aNum + 0.5;
       
   192 	Floor(aRes,temp);
       
   193 	}
       
   194 
       
   195 //------------------------------------------------------
       
   196 // Class:       TCalendar
       
   197 // Function:    JulianDay
       
   198 // Arguments:   None
       
   199 //
       
   200 // Comments:    Returns the Julian day as a TInt
       
   201 //
       
   202 // Return:      TInt
       
   203 //------------------------------------------------------
       
   204 TInt TCalendar::JulianDay()
       
   205 	{
       
   206 	return (TInt)iJulianDay;
       
   207 	}