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