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.
21 #include <FBaseTimeSpan.h>
22 #include <FBaseSysLog.h>
24 namespace Tizen { namespace Base
27 TimeSpan::TimeSpan(const TimeSpan& value)
28 : __ticks(value.__ticks)
29 , __pTimeSpanImpl(null)
33 TimeSpan::TimeSpan(int hours, int minutes, int seconds)
35 __pTimeSpanImpl = null;
36 __ticks = CalcTicks(0, hours, minutes, seconds, 0);
39 TimeSpan::TimeSpan(int days, int hours, int minutes, int seconds)
41 __pTimeSpanImpl = null;
42 __ticks = CalcTicks(days, hours, minutes, seconds, 0);
45 TimeSpan::TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds)
47 __pTimeSpanImpl = null;
48 __ticks = CalcTicks(days, hours, minutes, seconds, milliseconds);
51 TimeSpan::TimeSpan(long long ticks)
53 , __pTimeSpanImpl(null)
57 TimeSpan::~TimeSpan(void)
62 TimeSpan::operator +(const TimeSpan& rhs) const
64 return TimeSpan(__ticks + rhs.__ticks);
68 TimeSpan::operator -(const TimeSpan& rhs) const
70 return TimeSpan(__ticks - rhs.__ticks);
74 TimeSpan::operator =(const TimeSpan& rhs)
78 __ticks = rhs.__ticks;
84 TimeSpan::operator ==(const TimeSpan& rhs) const
86 return __ticks == rhs.__ticks;
90 TimeSpan::operator !=(const TimeSpan& rhs) const
92 return __ticks != rhs.__ticks;
96 TimeSpan::operator <(const TimeSpan& rhs) const
98 return __ticks < rhs.__ticks;
102 TimeSpan::operator >(const TimeSpan& rhs) const
104 return __ticks > rhs.__ticks;
108 TimeSpan::operator <=(const TimeSpan& rhs) const
110 return __ticks <= rhs.__ticks;
114 TimeSpan::operator >=(const TimeSpan& rhs) const
116 return __ticks >= rhs.__ticks;
120 TimeSpan::Compare(const TimeSpan& t1, const TimeSpan& t2)
122 if ((t1.__ticks - t2.__ticks) > 0)
126 else if ((t1.__ticks - t2.__ticks) < 0)
135 TimeSpan::CompareTo(const TimeSpan& value) const
137 return TimeSpan::Compare(*this, value);
141 TimeSpan::Equals(const Object& obj) const
143 const TimeSpan* pOther = dynamic_cast< const TimeSpan* >(&obj);
149 return *this == *pOther;
153 TimeSpan::Duration(void) const
155 return TimeSpan((__ticks >= 0 ? __ticks : -__ticks));
159 TimeSpan::GetHashCode(void) const
161 return(int((__ticks >> 32) ^ ((__ticks >> 32) >> 16)) ^ int((__ticks & 0x0000FFFF)));
165 TimeSpan::Negate(void) const
167 return TimeSpan(-__ticks);
171 TimeSpan::CalcTicks(int days, int hours, int minutes, int seconds, int milliseconds)
189 if (milliseconds < 0)
194 return (long long) ((NUM_OF_TICKS_IN_DAY * days) + (NUM_OF_TICKS_IN_HOUR * hours) + (NUM_OF_TICKS_IN_MINUTE * minutes) +
195 (NUM_OF_TICKS_IN_SECOND * seconds) + milliseconds);
199 TimeSpan::GetDays(void) const
201 return (long long) (__ticks / NUM_OF_TICKS_IN_DAY);
205 TimeSpan::GetHours(void) const
207 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
210 return (long long) (r / NUM_OF_TICKS_IN_HOUR);
216 TimeSpan::GetMinutes(void) const
218 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
221 r = r % NUM_OF_TICKS_IN_HOUR;
224 return (long long) (r / NUM_OF_TICKS_IN_MINUTE);
232 TimeSpan::GetSeconds(void) const
234 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
237 r = r % NUM_OF_TICKS_IN_HOUR;
240 r = r % NUM_OF_TICKS_IN_MINUTE;
243 return (long long) (r / NUM_OF_TICKS_IN_SECOND);
253 TimeSpan::GetMilliseconds(void) const
255 long long r = __ticks % NUM_OF_TICKS_IN_DAY;
258 r = r % NUM_OF_TICKS_IN_HOUR;
261 r = r % NUM_OF_TICKS_IN_MINUTE;
264 r = r % NUM_OF_TICKS_IN_SECOND;
275 TimeSpan::GetTicks(void) const