2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FBaseTimeSpan.cpp
20 * @brief This is the implementation file of TimeSpan class.
23 #include <FBaseTimeSpan.h>
24 #include <FBaseSysLog.h>
26 namespace Tizen { namespace Base
29 TimeSpan::TimeSpan(const TimeSpan& value)
30 : __ticks(value.__ticks)
31 , __pTimeSpanImpl(null)
35 TimeSpan::TimeSpan(int hours, int minutes, int seconds)
37 __pTimeSpanImpl = null;
38 __ticks = CalcTicks(0, hours, minutes, seconds, 0);
41 TimeSpan::TimeSpan(int days, int hours, int minutes, int seconds)
43 __pTimeSpanImpl = null;
44 __ticks = CalcTicks(days, hours, minutes, seconds, 0);
47 TimeSpan::TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds)
49 __pTimeSpanImpl = null;
50 __ticks = CalcTicks(days, hours, minutes, seconds, milliseconds);
53 TimeSpan::TimeSpan(long long ticks)
55 , __pTimeSpanImpl(null)
59 TimeSpan::~TimeSpan(void)
64 TimeSpan::operator +(const TimeSpan& rhs) const
66 return TimeSpan(__ticks + rhs.__ticks);
70 TimeSpan::operator -(const TimeSpan& rhs) const
72 return TimeSpan(__ticks - rhs.__ticks);
76 TimeSpan::operator =(const TimeSpan& rhs)
80 __ticks = rhs.__ticks;
86 TimeSpan::operator ==(const TimeSpan& rhs) const
88 return __ticks == rhs.__ticks;
92 TimeSpan::operator !=(const TimeSpan& rhs) const
94 return __ticks != rhs.__ticks;
98 TimeSpan::operator <(const TimeSpan& rhs) const
100 return __ticks < rhs.__ticks;
104 TimeSpan::operator >(const TimeSpan& rhs) const
106 return __ticks > rhs.__ticks;
110 TimeSpan::operator <=(const TimeSpan& rhs) const
112 return __ticks <= rhs.__ticks;
116 TimeSpan::operator >=(const TimeSpan& rhs) const
118 return __ticks >= rhs.__ticks;
122 TimeSpan::Compare(const TimeSpan& t1, const TimeSpan& t2)
124 if ((t1.__ticks - t2.__ticks) > 0)
128 else if ((t1.__ticks - t2.__ticks) < 0)
137 TimeSpan::CompareTo(const TimeSpan& value) const
139 return TimeSpan::Compare(*this, value);
143 TimeSpan::Equals(const Object& obj) const
145 const TimeSpan* pOther = dynamic_cast <const TimeSpan*>(&obj);
151 return *this == *pOther;
155 TimeSpan::Duration(void) const
157 return TimeSpan((__ticks >= 0 ? __ticks : -__ticks));
161 TimeSpan::GetHashCode(void) const
163 return(int((__ticks >> 32) ^ ((__ticks >> 32) >> 16)) ^ int((__ticks & 0x0000FFFF)));
167 TimeSpan::Negate(void) const
169 return TimeSpan(-__ticks);
173 TimeSpan::CalcTicks(int days, int hours, int minutes, int seconds, int milliseconds)
191 if (milliseconds < 0)
196 return (long long) ((NUM_OF_TICKS_IN_DAY * days) + (NUM_OF_TICKS_IN_HOUR * hours) + (NUM_OF_TICKS_IN_MINUTE * minutes) +
197 (NUM_OF_TICKS_IN_SECOND * seconds) + milliseconds);
201 TimeSpan::GetDays(void) const
203 return (long long) (__ticks / NUM_OF_TICKS_IN_DAY);
207 TimeSpan::GetHours(void) const
209 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
212 return (long long) (r / NUM_OF_TICKS_IN_HOUR);
218 TimeSpan::GetMinutes(void) const
220 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
223 r = r % NUM_OF_TICKS_IN_HOUR;
226 return (long long) (r / NUM_OF_TICKS_IN_MINUTE);
234 TimeSpan::GetSeconds(void) const
236 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
239 r = r % NUM_OF_TICKS_IN_HOUR;
242 r = r % NUM_OF_TICKS_IN_MINUTE;
245 return (long long) (r / NUM_OF_TICKS_IN_SECOND);
255 TimeSpan::GetMilliseconds(void) const
257 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
260 r = r % NUM_OF_TICKS_IN_HOUR;
263 r = r % NUM_OF_TICKS_IN_MINUTE;
266 r = r % NUM_OF_TICKS_IN_SECOND;
277 TimeSpan::GetTicks(void) const