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.h
20 * @brief This is the header file for the %TimeSpan class.
22 * This header file contains the declarations of the %TimeSpan class.
24 #ifndef _FBASE_TIME_SPAN_H_
25 #define _FBASE_TIME_SPAN_H_
27 #include <FBaseTypes.h>
28 #include <FBaseObject.h>
31 namespace Tizen { namespace Base
35 * @brief This class represents a time interval.
39 * The %TimeSpan class represents a time interval. An instance of %TimeSpan represents a period of time measured in ticks. A tick is the smallest
40 * unit of time used by the platform or system. In %Tizen, it is a millisecond.
42 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/datetime_timespan.htm">DateTime and TimeSpan</a>.
44 * The following example demonstrates how to use the %TimeSpan class.
49 * using namespace Tizen::Base;
52 * MyClass::TimeSpanSample(void)
54 * TimeSpan span1(1, 1, 1); // one hour + one minute + one second
55 * TimeSpan span2(1, 23, 70, 100); // 1 days + 23 hours + 70 minutes + 100 seconds
59 * TimeSpan span3 = (span2 - span1);
60 * if (TimeSpan::Compare(span1, span3) == 0)
67 * long long days, hours, minutes, seconds;
69 * days = span2.GetDays(); // 2 days
70 * hours = span2.GetHours(); // 0 hours
71 * minutes = span2.GetMinutes(); // 11 minutes
72 * seconds = span2.GetSeconds(); // 40 seconds
77 class _OSP_EXPORT_ TimeSpan
82 * Copying of objects using this copy constructor is allowed.
86 * @param[in] value An instance of %TimeSpan to copy
88 TimeSpan(const TimeSpan& value);
92 * Initializes an instance of %TimeSpan with the specified parameters.
96 * @param[in] hours The number of hours
97 * @param[in] minutes The number of minutes
98 * @param[in] seconds The number of seconds
100 TimeSpan(int hours, int minutes, int seconds);
104 * Initializes an instance of %TimeSpan with the specified parameters.
108 * @param[in] days The number of days
109 * @param[in] hours The number of hours
110 * @param[in] minutes The number of minutes
111 * @param[in] seconds The number of seconds
113 TimeSpan(int days, int hours, int minutes, int seconds);
117 * Initializes an instance of %TimeSpan with the specified parameters.
121 * @param[in] days The number of days
122 * @param[in] hours The number of hours
123 * @param[in] minutes The number of minutes
124 * @param[in] seconds The number of seconds
125 * @param[in] milliseconds The number of milliseconds
127 TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds);
131 * Initializes an instance of %TimeSpan with the specified number of ticks.
135 * @param[in] ticks The number of ticks (in milliseconds)
137 TimeSpan(long long ticks);
140 * This destructor overrides Tizen::Base::Object::~Object().
144 virtual ~TimeSpan(void);
147 * Adds the values of the two instances of %TimeSpan.
151 * @return An instance of %TimeSpan
152 * @param[in] rhs An instance of %TimeSpan to add
154 TimeSpan operator +(const TimeSpan& rhs) const;
157 * Subtracts the values of the two instances of %TimeSpan.
161 * @return An instance of %TimeSpan
162 * @param[in] rhs An instance of %TimeSpan to subtract
164 TimeSpan operator -(const TimeSpan& rhs) const;
167 * Copying of objects using this copy assignment operator is allowed.
171 * @return A reference to the current instance of %TimeSpan
172 * @param[in] rhs An instance of %TimeSpan
174 TimeSpan& operator =(const TimeSpan& rhs);
177 * Checks whether the value of this instance is equal to the value of the
178 * specified instance of %TimeSpan.
182 * @return @c true if the two values are equal, @n
184 * @param[in] rhs An instance of %TimeSpan to compare
186 bool operator ==(const TimeSpan& rhs) const;
189 * Checks whether the value of this instance is not equal to
190 * the value of the specified instance of %TimeSpan.
194 * @return @c true if the two values are not equal, @n
196 * @param[in] rhs An instance of %TimeSpan to compare
198 bool operator !=(const TimeSpan& rhs) const;
201 * Checks whether the value of the calling instance is less than that of
202 * the specified instance of %TimeSpan.
206 * @return @c true if the value of the calling instance is less than that of the specified instance of %TimeSpan, @n
208 * @param[in] rhs An instance of %TimeSpan to compare
210 bool operator <(const TimeSpan& rhs) const;
213 * Checks whether the value of the calling instance is greater than that of
214 * the specified instance of %TimeSpan.
218 * @return @c true if the value of the calling instance is greater than that of the specified instance of %TimeSpan, @n
220 * @param[in] rhs An instance of %TimeSpan to compare
222 bool operator >(const TimeSpan& rhs) const;
225 * Checks whether the value of the calling instance is less than or equal to
226 * the value of the specified instance of %TimeSpan.
230 * @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
232 * @param[in] rhs An instance of %TimeSpan to compare
234 bool operator <=(const TimeSpan& rhs) const;
237 * Checks whether the value of the calling instance is greater than or equal to
238 * the value of the specified instance of %TimeSpan.
242 * @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
244 * @param[in] rhs An instance of %TimeSpan to compare
246 bool operator >=(const TimeSpan& rhs) const;
249 * Compares the two specified instances of %TimeSpan.
253 * @return A 32-bit @c signed integer value
254 * @param[in] t1 An instance of %TimeSpan to compare
255 * @param[in] t2 An instance of %TimeSpan to compare
258 * < 0 if the value of @c t1 is less than the value of @c t2
259 * == 0 if the value of @c t1 is equal to the value of @c t2
260 * > 0 if the value of @c t1 is greater than the value of @c t2
263 static int Compare(const TimeSpan& t1, const TimeSpan& t2);
266 * Compares the value of the calling instance to the value of the specified instance.
270 * @return A 32-bit @c signed integer value
271 * @param[in] value An instance of %TimeSpan to compare
274 * < 0 if the value of the current instance is less than the value of @c obj
275 * == 0 if the value of the current instance is equal to the value of @c obj
276 * > 0 if the value of the current instance is greater than the value of @c obj
279 int CompareTo(const TimeSpan& value) const;
282 * Checks whether the specified instance of Object is equal to the current instance of %TimeSpan.
286 * @return @c true if the specified instance of Object is equal to the current instance of %TimeSpan, @n
288 * @param[in] obj An instance of Object to compare
289 * @see Tizen::Base::Object::GetHashCode()
291 virtual bool Equals(const Object& obj) const;
294 * Gets the absolute value of the calling instance.
298 * @return An instance of %TimeSpan containing the absolute value
299 * @remarks This method is used to get absolute difference between two %TimeSpan instances.
302 * TimeSpan t1(1000); // 1000 milliseconds
303 * TimeSpan t2(2000); // 2000 milliseconds
304 * TimeSpan t3 = t1 - t2; // t3 == -1000
305 * TimeSpan t4 = t3.Duration(); // t4 == 1000
308 TimeSpan Duration(void) const;
311 * Gets the hash value of the current instance.
315 * @return The hash value of the current instance
316 * @see Tizen::Base::Object::Equals()
318 virtual int GetHashCode(void) const;
321 * Gets the negative value of the calling instance.
325 * @return An instance of %Timespan containing the negative value of the calling instance
327 TimeSpan Negate(void) const;
330 * Gets the number of whole days represented by the calling instance.
334 * @return The number of whole days represented by the calling instance
336 long long GetDays(void) const;
339 * Gets the number of hours represented by the calling instance.
343 * @return The number of hours represented by the calling instance
345 long long GetHours(void) const;
348 * Gets the number of minutes represented by the calling instance.
352 * @return The number of minutes represented by the calling instance
354 long long GetMinutes(void) const;
357 * Gets the number of seconds represented by the calling instance.
361 * @return The number of seconds represented by the calling instance
363 long long GetSeconds(void) const;
366 * Gets the number of milliseconds represented by the calling instance.
370 * @return The number of milliseconds represented by the calling instance
372 long long GetMilliseconds(void) const;
375 * Gets the number of ticks represented by the calling instance.
379 * @return The number of ticks represented by the calling instance
381 long long GetTicks(void) const;
384 * A constant holding the number of ticks in a day.
388 static const long long NUM_OF_TICKS_IN_DAY = 86400000LL;
391 * A constant holding the number of ticks in an hour.
395 static const long long NUM_OF_TICKS_IN_HOUR = 3600000LL;
398 * A constant holding the number of ticks in a minute.
402 static const long long NUM_OF_TICKS_IN_MINUTE = 60000LL;
405 * A constant holding the number of ticks in a second.
409 static const long long NUM_OF_TICKS_IN_SECOND = 1000LL;
413 // Gets the numbers of ticks.
414 // @return The numbers of ticks
415 // @param[in] days The number of whole days
416 // @param[in] hours The number of hours
417 // @param[in] minutes The number of minutes
418 // @param[in] seconds The number of seconds
419 // @param[in] milliseconds The number of milliseconds
421 static long long CalcTicks(int days, int hours, int minutes, int seconds, int milliseconds);
425 friend class _TimeSpanImpl;
426 class _TimeSpanImpl * __pTimeSpanImpl;
432 #endif //_FBASE_TIME_SPAN_H_