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.h
19 * @brief This is the header file for the %TimeSpan class.
21 * This header file contains the declarations of the %TimeSpan class.
23 #ifndef _FBASE_TIME_SPAN_H_
24 #define _FBASE_TIME_SPAN_H_
26 #include <FBaseTypes.h>
27 #include <FBaseObject.h>
30 namespace Tizen { namespace Base
34 * @brief This class represents a time interval.
38 * The %TimeSpan class represents a time interval. An instance of %TimeSpan represents a period of time measured in ticks. A tick is the smallest
39 * unit of time used by the platform or system. In %Tizen, it is a millisecond.
41 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/datetime_timespan.htm">DateTime and TimeSpan</a>.
43 * The following example demonstrates how to use the %TimeSpan class.
48 * using namespace Tizen::Base;
51 * MyClass::TimeSpanSample(void)
53 * TimeSpan span1(1, 1, 1); // one hour + one minute + one second
54 * TimeSpan span2(1, 23, 70, 100); // 1 days + 23 hours + 70 minutes + 100 seconds
58 * TimeSpan span3 = (span2 - span1);
59 * if (TimeSpan::Compare(span1, span3) == 0)
66 * long long days, hours, minutes, seconds;
68 * days = span2.GetDays(); // 2 days
69 * hours = span2.GetHours(); // 0 hours
70 * minutes = span2.GetMinutes(); // 11 minutes
71 * seconds = span2.GetSeconds(); // 40 seconds
76 class _OSP_EXPORT_ TimeSpan
81 * Copying of objects using this copy constructor is allowed.
85 * @param[in] value An instance of %TimeSpan to copy
87 TimeSpan(const TimeSpan& value);
91 * Initializes an instance of %TimeSpan with the specified parameters.
95 * @param[in] hours The number of hours
96 * @param[in] minutes The number of minutes
97 * @param[in] seconds The number of seconds
99 TimeSpan(int hours, int minutes, int seconds);
103 * Initializes an instance of %TimeSpan with the specified parameters.
107 * @param[in] days The number of days
108 * @param[in] hours The number of hours
109 * @param[in] minutes The number of minutes
110 * @param[in] seconds The number of seconds
112 TimeSpan(int days, int hours, int minutes, int seconds);
116 * Initializes an instance of %TimeSpan with the specified parameters.
120 * @param[in] days The number of days
121 * @param[in] hours The number of hours
122 * @param[in] minutes The number of minutes
123 * @param[in] seconds The number of seconds
124 * @param[in] milliseconds The number of milliseconds
126 TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds);
130 * Initializes an instance of %TimeSpan with the specified number of ticks.
134 * @param[in] ticks The number of ticks (in milliseconds)
136 TimeSpan(long long ticks);
139 * This destructor overrides Tizen::Base::Object::~Object().
143 virtual ~TimeSpan(void);
146 * Adds the values of the two instances of %TimeSpan.
150 * @return An instance of %TimeSpan
151 * @param[in] rhs An instance of %TimeSpan to add
153 TimeSpan operator +(const TimeSpan& rhs) const;
156 * Subtracts the values of the two instances of %TimeSpan.
160 * @return An instance of %TimeSpan
161 * @param[in] rhs An instance of %TimeSpan to subtract
163 TimeSpan operator -(const TimeSpan& rhs) const;
166 * Copying of objects using this copy assignment operator is allowed.
170 * @return A reference to the current instance of %TimeSpan
171 * @param[in] rhs An instance of %TimeSpan
173 TimeSpan& operator =(const TimeSpan& rhs);
176 * Checks whether the value of this instance is equal to the value of the
177 * specified instance of %TimeSpan.
181 * @return @c true if the two values are equal, @n
183 * @param[in] rhs An instance of %TimeSpan to compare
185 bool operator ==(const TimeSpan& rhs) const;
188 * Checks whether the value of this instance is not equal to
189 * the value of the specified instance of %TimeSpan.
193 * @return @c true if the two values are not equal, @n
195 * @param[in] rhs An instance of %TimeSpan to compare
197 bool operator !=(const TimeSpan& rhs) const;
200 * Checks whether the value of the calling instance is less than
201 * the value of the specified instance of %TimeSpan.
205 * @return @c true if the value of the calling instance is less than the value of the specified instance of %TimeSpan, @n
207 * @param[in] rhs An instance of %TimeSpan to compare
209 bool operator <(const TimeSpan& rhs) const;
212 * Checks whether the value of the calling instance is greater than
213 * the value of the specified instance of %TimeSpan.
217 * @return @c true if the value of the calling instance is greater than the value of the specified instance of %TimeSpan, @n
219 * @param[in] rhs An instance of %TimeSpan to compare
221 bool operator >(const TimeSpan& rhs) const;
224 * Checks whether the value of the calling instance is less than or equal to
225 * the value of the specified instance of %TimeSpan.
229 * @return @c true if the value of the calling instance is less than or equal to the value of the specified instance of %TimeSpan, @n
231 * @param[in] rhs An instance of %TimeSpan to compare
233 bool operator <=(const TimeSpan& rhs) const;
236 * Checks whether the value of the calling instance is greater than or equal to
237 * the value of the specified instance of %TimeSpan.
241 * @return @c true if the value of the calling instance is greater than or equal to the value of the specified instance of %TimeSpan, @n
243 * @param[in] rhs An instance of %TimeSpan to compare
245 bool operator >=(const TimeSpan& rhs) const;
248 * Compares the two specified instances of %TimeSpan.
252 * @return The 32-bit @c signed integer value
253 * @param[in] t1 An instance of %TimeSpan to compare
254 * @param[in] t2 An instance of %TimeSpan to compare
257 * < 0 if the value of t1 is less than the value of t2
258 * == 0 if the value of t1 is equal to the value of t2
259 * > 0 if the value of t1 is greater than the value of t2
262 static int Compare(const TimeSpan& t1, const TimeSpan& t2);
265 * Compares the value of the calling instance to the value of the specified instance.
269 * @return The 32-bit @c signed integer value
270 * @param[in] value An instance of %TimeSpan to compare
273 * < 0 if the value of the current instance is less than the value of obj
274 * == 0 if the value of the current instance is equal to the value of obj
275 * > 0 if the value of the current instance is greater than the value of obj
278 int CompareTo(const TimeSpan& value) const;
281 * Checks whether the specified instance of Object is equal to the current instance of %TimeSpan.
285 * @return @c true if the specified instance of Object is equal to the current instance of %TimeSpan, @n
287 * @param[in] obj An instance of Object to compare
288 * @see Tizen::Base::Object::GetHashCode()
290 virtual bool Equals(const Object& obj) const;
293 * Gets the absolute value of the calling instance.
297 * @return An instance of %TimeSpan that contains the absolute value
298 * @remarks This method is used to get the absolute difference between two %TimeSpan instances.
301 * TimeSpan t1(1000); // 1000 milliseconds
302 * TimeSpan t2(2000); // 2000 milliseconds
303 * TimeSpan t3 = t1 - t2; // t3 == -1000
304 * TimeSpan t4 = t3.Duration(); // t4 == 1000
307 TimeSpan Duration(void) const;
310 * Gets the hash value of the current instance.
314 * @return The hash value of the current instance
315 * @see Tizen::Base::Object::Equals()
317 virtual int GetHashCode(void) const;
320 * Gets the negative value of the calling instance.
324 * @return An instance of %Timespan that contains the negative value of the calling instance
326 TimeSpan Negate(void) const;
329 * Gets the number of whole days represented by the calling instance.
333 * @return The number of whole days represented by the calling instance
335 long long GetDays(void) const;
338 * Gets the number of hours represented by the calling instance.
342 * @return The number of hours represented by the calling instance
344 long long GetHours(void) const;
347 * Gets the number of minutes represented by the calling instance.
351 * @return The number of minutes represented by the calling instance
353 long long GetMinutes(void) const;
356 * Gets the number of seconds represented by the calling instance.
360 * @return The number of seconds represented by the calling instance
362 long long GetSeconds(void) const;
365 * Gets the number of milliseconds represented by the calling instance.
369 * @return The number of milliseconds represented by the calling instance
371 long long GetMilliseconds(void) const;
374 * Gets the number of ticks represented by the calling instance.
378 * @return The number of ticks represented by the calling instance
380 long long GetTicks(void) const;
383 * The constant holding the number of ticks in a day.
387 static const long long NUM_OF_TICKS_IN_DAY = 86400000LL;
390 * The constant holding the number of ticks in an hour.
394 static const long long NUM_OF_TICKS_IN_HOUR = 3600000LL;
397 * The constant holding the number of ticks in a minute.
401 static const long long NUM_OF_TICKS_IN_MINUTE = 60000LL;
404 * The constant holding the number of ticks in a second.
408 static const long long NUM_OF_TICKS_IN_SECOND = 1000LL;
412 // Gets the numbers of ticks.
413 // @return The numbers of ticks
414 // @param[in] days The number of whole days
415 // @param[in] hours The number of hours
416 // @param[in] minutes The number of minutes
417 // @param[in] seconds The number of seconds
418 // @param[in] milliseconds The number of milliseconds
420 static long long CalcTicks(int days, int hours, int minutes, int seconds, int milliseconds);
424 friend class _TimeSpanImpl;
425 class _TimeSpanImpl * __pTimeSpanImpl;
431 #endif //_FBASE_TIME_SPAN_H_