2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FBaseTimeSpan.cpp
19 * @brief This is the implementation file of TimeSpan class.
22 #include <FBaseTimeSpan.h>
23 #include <FBaseSysLog.h>
25 namespace Tizen { namespace Base
28 TimeSpan::TimeSpan(const TimeSpan& value)
29 : __ticks(value.__ticks)
30 , __pTimeSpanImpl(null)
34 TimeSpan::TimeSpan(int hours, int minutes, int seconds)
36 __pTimeSpanImpl = null;
37 __ticks = CalcTicks(0, hours, minutes, seconds, 0);
40 TimeSpan::TimeSpan(int days, int hours, int minutes, int seconds)
42 __pTimeSpanImpl = null;
43 __ticks = CalcTicks(days, hours, minutes, seconds, 0);
46 TimeSpan::TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds)
48 __pTimeSpanImpl = null;
49 __ticks = CalcTicks(days, hours, minutes, seconds, milliseconds);
52 TimeSpan::TimeSpan(long long ticks)
54 , __pTimeSpanImpl(null)
58 TimeSpan::~TimeSpan(void)
63 TimeSpan::operator +(const TimeSpan& rhs) const
65 return TimeSpan(__ticks + rhs.__ticks);
69 TimeSpan::operator -(const TimeSpan& rhs) const
71 return TimeSpan(__ticks - rhs.__ticks);
75 TimeSpan::operator =(const TimeSpan& rhs)
79 __ticks = rhs.__ticks;
85 TimeSpan::operator ==(const TimeSpan& rhs) const
87 return __ticks == rhs.__ticks;
91 TimeSpan::operator !=(const TimeSpan& rhs) const
93 return __ticks != rhs.__ticks;
97 TimeSpan::operator <(const TimeSpan& rhs) const
99 return __ticks < rhs.__ticks;
103 TimeSpan::operator >(const TimeSpan& rhs) const
105 return __ticks > rhs.__ticks;
109 TimeSpan::operator <=(const TimeSpan& rhs) const
111 return __ticks <= rhs.__ticks;
115 TimeSpan::operator >=(const TimeSpan& rhs) const
117 return __ticks >= rhs.__ticks;
121 TimeSpan::Compare(const TimeSpan& t1, const TimeSpan& t2)
123 if ((t1.__ticks - t2.__ticks) > 0)
127 else if ((t1.__ticks - t2.__ticks) < 0)
136 TimeSpan::CompareTo(const TimeSpan& value) const
138 return TimeSpan::Compare(*this, value);
142 TimeSpan::Equals(const Object& obj) const
144 const TimeSpan* pOther = dynamic_cast <const TimeSpan*>(&obj);
150 return *this == *pOther;
154 TimeSpan::Duration(void) const
156 return TimeSpan((__ticks >= 0 ? __ticks : -__ticks));
160 TimeSpan::GetHashCode(void) const
162 return(int((__ticks >> 32) ^ ((__ticks >> 32) >> 16)) ^ int((__ticks & 0x0000FFFF)));
166 TimeSpan::Negate(void) const
168 return TimeSpan(-__ticks);
172 TimeSpan::CalcTicks(int days, int hours, int minutes, int seconds, int milliseconds)
190 if (milliseconds < 0)
195 return (long long) ((NUM_OF_TICKS_IN_DAY * days) + (NUM_OF_TICKS_IN_HOUR * hours) + (NUM_OF_TICKS_IN_MINUTE * minutes) +
196 (NUM_OF_TICKS_IN_SECOND * seconds) + milliseconds);
200 TimeSpan::GetDays(void) const
202 return (long long) (__ticks / NUM_OF_TICKS_IN_DAY);
206 TimeSpan::GetHours(void) const
208 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
211 return (long long) (r / NUM_OF_TICKS_IN_HOUR);
217 TimeSpan::GetMinutes(void) const
219 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
222 r = r % NUM_OF_TICKS_IN_HOUR;
225 return (long long) (r / NUM_OF_TICKS_IN_MINUTE);
233 TimeSpan::GetSeconds(void) const
235 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
238 r = r % NUM_OF_TICKS_IN_HOUR;
241 r = r % NUM_OF_TICKS_IN_MINUTE;
244 return (long long) (r / NUM_OF_TICKS_IN_SECOND);
254 TimeSpan::GetMilliseconds(void) const
256 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
259 r = r % NUM_OF_TICKS_IN_HOUR;
262 r = r % NUM_OF_TICKS_IN_MINUTE;
265 r = r % NUM_OF_TICKS_IN_SECOND;
276 TimeSpan::GetTicks(void) const