Merge "Remove the memory leak on osp-security-service" into tizen_2.2
[platform/framework/native/appfw.git] / inc / FBaseDateTime.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FBaseDateTime.h
19  * @brief               This is the header file for the %DateTime class.
20  *
21  * This header file contains the declarations of the %DateTime class.
22  */
23 #ifndef _FBASE_DATE_TIME_H_
24 #define _FBASE_DATE_TIME_H_
25
26 #include <FBaseObject.h>
27 #include <FBaseTimeSpan.h>
28 #include <FBaseString.h>
29 #include <FBaseDouble.h>
30
31 namespace Tizen { namespace Base
32 {
33 /**
34  *      @class  DateTime
35  *      @brief  This class represents the date and time as per the Gregorian calendar.
36  *
37  *      @since 2.0
38  *
39  *      The %DateTime class represents dates and times with values ranging from 12:00:00.000 midnight,
40  *      January 1, 1 to 11:59:59.999 P.M., December 31, 9999 in the Gregorian calendar. It
41  *      provides methods for conversion between the time formats.
42  *
43  *      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  *
45  *  The following example demonstrates how to use the %DateTime class.
46
47  *      @code
48  *
49  *      #include <FBase.h>
50  *
51  *      using namespace Tizen::Base;
52  *
53  *      // This method sets both current local time and UTC time.
54  *      void
55  *      MyClass::DateTimeSample(void)
56  *      {
57  *              DateTime dt;
58  *              int year, month, day;
59  *
60  *              dt.SetValue(2009, 10, 25);
61  *
62  *              dt.AddYears(10);
63  *              dt.AddMonths(3);
64  *              dt.AddDays(5);
65  *
66  *              // Gets values
67  *              year = dt.GetYear();            //      2020
68  *              month = dt.GetMonth();          //      1
69  *              day = dt.GetDay();                      //      30
70  *      }
71  *      @endcode
72  */
73 class _OSP_EXPORT_ DateTime
74         : public Object
75 {
76 public:
77         /**
78          *      This is the default constructor for this class.
79          *
80          *      @since 2.0
81          *
82          *      @remarks        The value of the instance is the same as the value of the instance returned by the GetMinValue() method.
83          */
84         DateTime(void);
85
86         /**
87          *      Copying of objects using this copy constructor is allowed.
88          *
89          *      @since 2.0
90          *
91          *      @param[in]  value               The %DateTime instance to copy
92          */
93         DateTime(const DateTime& value);
94
95         /**
96          * This destructor overrides Tizen::Base::Object::~Object().
97          *
98          * @since 2.0
99          */
100         virtual ~DateTime(void);
101
102         /**
103          *      Sets the current instance of %DateTime to the value of the specified instance of TimeSpan since the minimum date (GetMinValue()).
104          *
105          *      @since 2.0
106          *
107          *      @param[in]      value                           An instance of TimeSpan
108          *      @exception      E_SUCCESS                       The method is successful.
109          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
110          *                                                                      - The specified @c value is outside the valid range defined by the method.
111          *                                                                      - The resulting value of %DateTime is greater than the value returned by GetMaxValue().
112      *                                                                  - The resulting value of %DateTime is less than the value returned by GetMinValue().
113          */
114         result SetValue(const TimeSpan& value);
115
116         /**
117          *      Sets the current instance of %DateTime to the value of the specified instance of %DateTime.
118          *
119          *      @since 2.0
120          *
121          *      @param[in]      value   An instance of %DateTime
122          */
123         void SetValue(const DateTime& value);
124
125         /**
126          *      Sets the current instance of %DateTime to the specified year, month, day, hour, minute, and second.
127          *
128          *      @since 2.0
129          *
130          *      @return         An error code
131          *      @param[in]      year                            The year to set
132          *      @param[in]      month                           The month to set
133          *      @param[in]      day                                     The day to set
134          *      @param[in]      hour                            The hour to set
135          *      @param[in]      minute                          The minute set
136          *      @param[in]      second                          The second to set
137          *      @exception      E_SUCCESS                       The method is successful.
138          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
139          *                                                                      - The value of the arguments is outside the valid range defined by the method.
140          *                                                                      - Either the arguments are greater than the value returned by GetMaxValue() or
141          *                                                                        less than the value returned by GetMinValue().
142          *                                                                      - The arguments contain invalid values,
143          *                                                                        for example, @c day is @c 31 when @c month is @c 2.
144          */
145         result SetValue(int year, int month, int day, int hour = 0, int minute = 0, int second = 0);
146
147         /**
148          *      Sets the current instance of %DateTime to the specified year, month, day, hour, minute, second, and millisecond.
149          *
150          *      @since 2.1
151          *
152          *      @return         An error code
153          *      @param[in]      year                            The year to set
154          *      @param[in]      month                           The month to set
155          *      @param[in]      day                                     The day to set
156          *      @param[in]      hour                            The hour to set
157          *      @param[in]      minute                          The minute set
158          *      @param[in]      second                          The second to set
159          *      @param[in]      millisecond                     The millisecond to set
160          *      @exception      E_SUCCESS                       The method is successful.
161          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
162          *                                                                      - The value of the arguments is outside the valid range defined by the method.
163          *                                                                      - Either the arguments are greater than the value returned by GetMaxValue() or
164          *                                                                        less than the value returned by GetMinValue().
165          *                                                                      - The arguments contain invalid values,
166          *                                                                        for example, @c day is @c 31 when @c month is @c 2.
167          */
168         result SetValue(int year, int month, int day, int hour, int minute, int second, int millisecond);
169
170         /**
171          *      Sets the current instance of %DateTime with the specified number of ticks.
172          *      The tick value of type @c long @c long represents dates and times ranging from January 1, 1 A.D. 00:00:00.000 am.
173          *
174          *      @since  2.1
175          *
176          *      @return         An error code
177          *      @param[in]      ticks                           The number of ticks
178          *      @exception      E_SUCCESS                       The method is successful.
179          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
180          *                                                                      - The value of the arguments is outside the valid range defined by the method.
181          *                                                                      - Either the arguments are greater than the value returned by GetMaxValue() or
182          *                                                                        less than the value returned by GetMinValue().
183          *                                                                      - The arguments contain invalid values,
184          *                                                                        for example, @c day is @c 31 when @c month is @c 2.
185          */
186         result SetValue(long long ticks);
187
188         /**
189          *      Copying of objects using this copy assignment operator is allowed.
190          *
191          *      @since 2.0
192          *
193          *      @return         A reference to the current object
194          *      @param[in]      rhs     An instance of %DateTime to copy
195          */
196         DateTime& operator =(const DateTime& rhs);
197
198         /**
199          *      Checks whether the current instance of %DateTime is equivalent to the specified instance of %DateTime.
200          *
201          *      @since 2.0
202          *
203          *      @return         @c true if the current instance is equivalent to the specified instance, @n
204          *                              else @c false
205          *      @param[in]      rhs     An instance of %DateTime to compare
206          */
207         bool operator ==(const DateTime& rhs) const;
208
209         /**
210          *      Checks whether the current instance of %DateTime is not equivalent to the specified instance of %DateTime.
211          *
212          *      @since 2.0
213          *
214          *      @return         @c true if the current instance is not equivalent to the specified instance, @n
215          *                              else @c false
216          *      @param[in]      rhs     An instance of %DateTime to compare
217          */
218         bool operator !=(const DateTime& rhs) const;
219
220         /**
221          *      Checks whether the value of the current instance of %DateTime is less than the value of the specified instance of %DateTime.
222          *
223          *      @since 2.0
224          *
225          *      @return         @c true if the value of the current instance is less than the value of the specified instance, @n
226          *                              else @c false
227          *      @param[in]      rhs     An instance of %DateTime to compare
228          */
229         bool operator <(const DateTime& rhs) const;
230
231         /**
232          *      Checks whether the value of the current instance of %DateTime is greater than the value of the specified instance of %DateTime.
233          *
234          *      @since 2.0
235          *
236          *      @return         @c true if the value of the current instance is greater than the value of the specified instance, @n
237          *                              else @c false
238          *      @param[in]      rhs     An instance of %DateTime to compare
239          */
240         bool operator >(const DateTime& rhs) const;
241
242         /**
243          *      Checks whether the value of the current instance of %DateTime is less than or equal to the value of the specified instance of %DateTime.
244          *
245          *      @since 2.0
246          *
247          *      @return         @c true if the value of the current instance is less than or equal to the value of the specified instance, @n
248          *                              else @c false
249          *      @param[in]      rhs     An instance of %DateTime to compare
250          */
251         bool operator <=(const DateTime& rhs) const;
252
253         /**
254          *      Checks whether the value of the current instance of %DateTime is greater than or equal to the value of the specified instance of %DateTime.
255          *
256          *      @since 2.0
257          *
258          *      @return         @c true if the value of the current instance is greater than or equal to the value of the specified instance, @n
259          *                              else @c false
260          *      @param[in]      rhs     An instance of %DateTime to compare
261          */
262         bool operator >=(const DateTime& rhs) const;
263
264         /**
265          *      Adds the specified time span to the instance of %DateTime.
266          *
267          *      @since 2.0
268          *
269          *      @return         An error code
270          *      @param[in]      t                                       The time span to add
271          *      @exception      E_SUCCESS                       The method is successful.
272          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
273          *                                                                      - The value of the argument is outside the valid range defined by the method.
274          *                                                                      - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue() or @n
275          *                                                                        less than the value returned by GetMinValue().
276          */
277         result Add(const TimeSpan& t);
278
279         /**
280          *      Adds the specified number of days to the instance of %DateTime.
281          *
282          *      @since 2.0
283          *
284          *      @return         An error code
285          *      @param[in]      days                            The number of days to add
286          *      @exception      E_SUCCESS                       The method is successful.
287          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
288          *                                                                      - The value of the argument is outside the valid range defined by the method.
289          *                                                                      - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue() or @n
290          *                                                                        less than the value returned by GetMinValue().
291          */
292         result AddDays(int days);
293
294         /**
295          *      Adds the specified number of hours to the instance of %DateTime.
296          *
297          *      @since 2.0
298          *
299          *      @return         An error code
300          *      @param[in]      hours                           The number of hours to add
301          *      @exception      E_SUCCESS                       The method is successful.
302          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
303          *                                                                      - The value of the argument is outside the valid range defined by the method.
304          *                                                                      - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue() or @n
305          *                                                                        less than the value returned by GetMinValue().
306          */
307         result AddHours(int hours);
308
309         /**
310          *      Adds the specified number of minutes to the instance of %DateTime.
311          *
312          *      @since 2.0
313          *
314          *      @return         An error code
315          *      @param[in]      minutes                         The number of minutes to add
316          *      @exception      E_SUCCESS                       The method is successful.
317          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
318          *                                                                      - The value of the argument is outside the valid range defined by the method.
319          *                                                                      - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue() or @n
320          *                                                                        less than the value returned by GetMinValue().
321          */
322         result AddMinutes(int minutes);
323
324         /**
325          *      Adds the specified number of months to the instance of %DateTime.
326          *
327          *      @since 2.0
328          *
329          *      @return         An error code
330          *      @param[in]      months                          The number of months to add
331          *      @exception      E_SUCCESS                       The method is successful.
332          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
333          *                                                                      - The value of the argument is outside the valid range defined by the method.
334          *                                                                      - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue() or @n
335          *                                                                        or less than the value returned by GetMinValue().
336          */
337         result AddMonths(int months);
338
339         /**
340          *      Adds the specified number of seconds to the instance of %DateTime.
341          *
342          *      @since 2.0
343          *
344          *      @return         An error code
345          *      @param[in]      seconds                         The number of seconds to add
346          *      @exception      E_SUCCESS                       The method is successful.
347          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
348          *                                                                      - The value of the argument is outside the valid range defined by the method.
349          *                                                                      - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue() or @n
350          *                                                                        less than the value returned by GetMinValue().
351          */
352         result AddSeconds(int seconds);
353
354         /**
355          *      Adds the specified number of milliseconds to the instance of %DateTime.
356          *
357          *      @since 2.1
358          *
359          *      @return         An error code
360          *      @param[in]      milliseconds            The number of milliseconds to add
361          *      @exception      E_SUCCESS                       The method is successful.
362          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
363          *                                                                      - The value of the argument is outside the valid range defined by the method.
364          *                                                                      - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue() or @n
365          *                                                                        less than the value returned by GetMinValue().
366          */
367         result AddMilliseconds(long long milliseconds);
368
369         /**
370          *      Adds the specified number of ticks to the instance of %DateTime.
371          *
372          *      @since 2.1
373          *
374          *      @return         An error code
375          *      @param[in]      ticks                           The number of ticks to add
376          *      @exception      E_SUCCESS                       The method is successful.
377          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
378          *                                                                      - The value of the argument is outside the valid range defined by the method.
379          *                                                                      - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue() or @n
380          *                                                                        less than the value returned by GetMinValue().
381          */
382         result AddTicks(long long ticks);
383
384         /**
385          *      Adds the specified number of years to the instance of %DateTime.
386          *
387          *      @since 2.0
388          *
389          *      @return         An error code
390          *      @param[in]      years                           The number of years to add
391          *      @exception      E_SUCCESS                       The method is successful.
392          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
393          *                                                                      - The value of the argument is outside the valid range defined by the method.
394          *                                                                      - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue() or @n
395          *                                                                        less than the value returned by GetMinValue().
396          */
397         result AddYears(int years);
398
399         /**
400          *      Compares two specified instances of %DateTime. @n
401          *      The two instances must be in the same time zone to make a meaningful comparison.
402          *
403          *      @since 2.0
404          *
405          *  @return             The 32-bit @c signed integer value
406          *      @code
407          *      <  0  if the value of dt1 is less than the value of dt2
408          *      == 0  if the value of dt1 is equal to the value of dt2
409          *      >  0  if the value of dt1 is greater than the value of dt2
410          *      @endcode
411          *      @param[in]      dt1     An instance of %DateTime
412          *      @param[in]      dt2     An instance of %DateTime
413          */
414         static int Compare(const DateTime& dt1, const DateTime& dt2);
415
416         /**
417          *      Compares the value of the current instance of %DateTime with the value of the specified instance of %DateTime.
418          *
419          *      @since 2.0
420          *
421          *  @return             The 32-bit @c signed integer value
422          *      @code
423          *      <  0  if the value of the current instance is less than value of the specified instance
424          *      == 0  if the value of the current instance is equal to value of the specified instance
425          *      >  0  if the value of the current instance is greater than value of the specified instance
426          *      @endcode
427          *      @param[in]      value   An instance of %DateTime
428          */
429         int CompareTo(const DateTime& value) const;
430
431         /**
432          *      Checks whether the specified instance of Object is equivalent to the current instance of %DateTime.
433          *
434          *      @since 2.0
435          *
436          *      @return         @c true if the specified instance of Object is equivalent to the current instance of %DateTime, @n
437          *                              else @c false
438          *      @param[in]      obj The object to compare with the current instance of %DateTime
439          *      @see            Tizen::Base::Object::GetHashCode()
440          */
441         virtual bool Equals(const Object& obj) const;
442
443         /**
444          *      Gets the hash value of the current instance of %DateTime. @n
445          *      The hash value is calculated as (GetTime() ^ (GetTime() >> 16)).
446          *
447          *      @since 2.0
448          *
449          *      @return         The hash value of the current instance of %DateTime
450          *      @see            Tizen::Base::Object::Equals()
451          */
452         virtual int GetHashCode(void) const;
453
454         /**
455          *      Gets the time span since the midnight of the date represented by the current instance of %DateTime.
456          *
457          *      @since 2.0
458          *
459          *      @return         An instance of TimeSpan
460          */
461         TimeSpan GetTimeOfDay(void) const;
462
463         /**
464          *      Gets the number of days in the specified month of the specified year.
465          *
466          *      @since 2.0
467          *
468          *      @return         An error code
469          *      @param[in]      year                            The year
470          *      @param[in]      month                           The month
471          *      @param[out]     days                            The number of days
472          *      @exception      E_SUCCESS                       The method is successful.
473          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
474          *                                                                      - The value of the argument is outside the valid range defined by the method.
475          *                                                                      - The specified @c year must be a value between @c 1 and @c 9999 and @c month must be a value between @c 1 and @c 12.
476          */
477         static result GetDaysInMonth(int year, int month, int& days);
478
479         /**
480          *      Subtracts the specified time span from the value of the current instance of %DateTime.
481          *
482          *      @since 2.0
483          *
484          *      @return         An error code
485          *      @param[in]      t                                       The time span to subtract
486          *      @exception      E_SUCCESS                       The method is successful.
487          *      @exception      E_OUT_OF_RANGE          Either of the following conditions has occurred:
488          *                                                                      - The value of the argument is outside the valid range defined by the method.
489          *                                                                      - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue() or @n
490          *                                                                        less than the value returned by GetMinValue().
491          */
492         result Subtract(const TimeSpan& t);
493
494         /**
495          *      Represents the current instance of %DateTime as a string.
496          *
497          *      @since 2.0
498          *
499          *      @return         The string that contains the Unicode representation of the value of the current instance of %DateTime
500          *      @remarks
501          *                              - The format of the String representation is "mm/dd/yyyy hh:mm:ss".
502          *                              - Use the Tizen::Locale namespace for a string of the locale-specific representation.
503          *
504          */
505         String ToString(void) const;
506
507         /**
508          * Parses the specified String representation of the date and time value.
509          *
510          * @since 2.0
511          *
512          * @return              An error code
513          * @param[in]   str                                             The String representation of the date and time value
514          * @param[out]  dt                                              The result of the method
515          * @exception   E_SUCCESS                               The method is successful.
516          * @exception   E_INVALID_FORMAT                The specified string is in an invalid format.
517          * @exception   E_OUT_OF_RANGE                  Either of the following conditions has occurred:
518          *                                                                              - The specified string contains an invalid value.
519          *                                                                              - Either the resulting value of %DateTime is greater than the value returned by GetMaxValue()
520          *                                                                                or less than the value returned by GetMinValue().
521          *                                                                              - The specified string contains an invalid value,
522          *                                                                                for example, @c day is @c 31 when the @c month is @c 2.
523          * @remarks
524          *                              - The format of the string is "mm/dd/yyyy hh:mm:ss".
525          *                              - This method guarantees that the original value of the out-parameter is not changed when the method returns an error.
526          */
527         static result Parse(const String& str, DateTime& dt);
528
529         /**
530          *      Gets the year of the current instance of %DateTime.
531          *
532          *      @since 2.0
533          *
534          *      @return         The integer value that indicates the year of the current instance of %DateTime
535          */
536         int GetYear(void) const;
537
538         /**
539          *      Gets the month of the current instance of %DateTime.
540          *
541          *      @since 2.0
542          *
543          *      @return         The integer value that indicates the month of the current instance of %DateTime
544          */
545         int GetMonth(void) const;
546
547         /**
548          *      Gets the day of the current instance of %DateTime.
549          *
550          *      @since 2.0
551          *
552          *      @return         The integer value that indicates the day of the current instance of %DateTime
553          */
554         int GetDay(void) const;
555
556         /**
557          *      Gets the hour of the current instance of %DateTime.
558          *
559          *      @since 2.0
560          *
561          *      @return         The integer value that indicates the hour of the current instance of %DateTime
562          */
563         int GetHour(void) const;
564
565         /**
566          *      Gets the minute of the current instance of %DateTime.
567          *
568          *      @since 2.0
569          *
570          *      @return         The integer value that indicates the minute of the current instance of %DateTime
571          */
572         int GetMinute(void) const;
573
574         /**
575          *      Gets the second of the current instance of %DateTime.
576          *
577          *      @since 2.0
578          *
579          *      @return         The integer value that indicates the second of the current instance of %DateTime
580          */
581         int GetSecond(void) const;
582
583         /**
584          *      Gets the millisecond of the current instance of %DateTime.
585          *
586          *      @since  2.1
587          *
588          *      @return         The integer value that indicates the millisecond of the current instance of %DateTime
589          */
590         int GetMillisecond(void) const;
591
592         /**
593          *      Gets the number of ticks in one second.
594          *
595          *      @since  2.1
596          *
597          *      @return         The number of ticks in one second.
598          */
599         static int GetTicksPerSecond(void);
600
601         /**
602          *      Gets the tick of the current instance of %DateTime.
603          *      The tick value of type @c long @c long represents dates and times ranging from January 1, 1 A.D. 00:00:00.000 am.
604          *
605          *      @since  2.1
606          *
607          *      @return         The @c long @c long value that indicates the tick of the current instance of %DateTime
608          */
609         long long GetTicks(void) const;
610
611         /**
612          *      Gets the number of milliseconds (in TimeSpan) since the minimum date (GetMinValue()).
613          *
614          *      @since 2.0
615          *
616          *      @return         An instance of TimeSpan
617          *      @remarks        The returned instance is the time since the value returned by GetMinValue().
618          */
619         TimeSpan GetTime(void) const;
620
621         /**
622          *      Gets the maximum allowable value of %DateTime (that is, "December 31 9999 23:59:59.999").
623          *
624          *      @since 2.0
625          *
626          *      @return         An instance of %DateTime
627          */
628         static const DateTime& GetMaxValue(void);
629
630         /**
631          *      Gets the minimum allowable value of %DateTime (that is, "January 1 1 00:00:00.000").
632          *
633          *      @since 2.0
634          *
635          *      @return         An instance of %DateTime
636          */
637         static const DateTime& GetMinValue(void);
638
639         /**
640          *      Checks whether the year represented by the current instance of %DateTime is a leap year.
641          *
642          *      @since 2.0
643          *
644          *      @return         @c true if the year represented by the current instance of %DateTime is a leap year, @n
645          *                              else @c false
646          */
647         bool IsLeapYear(void) const;
648
649         /**
650          *      Checks whether the specified year is a leap year.
651          *
652          *      @since 2.0
653          *
654          *      @return         @c true if the specified year is a leap year, @n
655          *                              else @c false
656          *      @param[in]      year    The year
657          */
658         static bool IsLeapYear(int year);
659
660 private:
661         DateTime(int year, int month, int day, int hour, int minute, int second, int tick);
662
663         int CountLeapYear(int year) const
664         {
665                 return static_cast< int >((year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400);
666         }
667
668         int CountDays(int year) const
669         {
670                 return static_cast< int >((year - 1) * 365 + CountLeapYear(year));
671         }
672
673         int CountYears(int day) const
674         {
675                 double year = (day - CountLeapYear(day / 365)) / 365.0;
676                 Double year1(year);
677                 Double year2(0.0);
678
679                 if (year1.Equals(year2))
680                 {
681                         return 1;
682                 }
683                 else
684                 {
685                         year = (year != static_cast< int >(year) ? 1 + static_cast< int >(year) : static_cast< int >(year));
686                         int tempDays = day - CountDays(year);
687
688                         // Check the boundary of days
689                         if (IsLeapYear(year))
690                         {
691                                 if (tempDays > 366)
692                                 {
693                                         year += 1;
694                                 }
695                         }
696                         else
697                         {
698                                 if (tempDays > 365)
699                                 {
700                                         year += 1;
701                                 }
702                         }
703
704                         return year;
705                 }
706         }
707
708         typedef struct
709         {
710                 int year;       /**<The year (1-9999)*/
711                 int month;      /**<The month (1-12)*/
712                 int day;        /**<The day (1-31)*/
713                 int hour;       /**<The hour (0-23)*/
714                 int minute;     /**<The minute (0-59)*/
715                 int second;     /**<The first 16 bits store tick (0-999) and the last 16 bits store second (0-59)*/
716         } TmDateTime;
717
718         result ConvertTicksToDate(long long ticks, TmDateTime* pDateTime);
719         long long ConvertDateToTicks(const TmDateTime* pDateTime) const;
720
721         result ConvertSecondsToDate(long long seconds, TmDateTime* pDateTime);
722         long long ConvertDateToSeconds(const TmDateTime* pDateTime) const;
723
724         TmDateTime __dateTime;
725
726         friend class _DateTimeImpl;
727         class _DateTimeImpl* __pDateTimeImpl;
728
729 }; // DateTime
730 }}  // Tizen::Base
731 #endif // _FBASE_DATE_TIME_H_