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 FBaseDateTime.cpp
20 * @brief This file contains implementation of DateTime class
25 #include <FBaseDateTime.h>
26 #include <FBaseResult.h>
27 #include <FBaseSysLog.h>
28 #include <unique_ptr.h>
30 namespace Tizen { namespace Base
49 NUM_OF_SEC_IN_DAY = 86400,
50 NUM_OF_SEC_IN_HOUR = 3600,
51 NUM_OF_SEC_IN_MINUTE = 60,
52 NUM_OF_TICKS_IN_DAY = 86400000LL,
53 NUM_OF_TICKS_IN_HOUR = 3600000LL,
54 NUM_OF_TICKS_IN_MINUTE = 60000LL,
55 NUM_OF_TICKS_IN_SECOND = 1000LL
58 static const int TICKS_PER_MILLISECOND = 1;
59 static const long SEC_IN_A_DAY = (24L * 60L * 60L);
60 static const long long MINIMUM_VALUE_IN_SEC = 86400LL;
61 static const int DAYS_IN_LEAP_YEAR[] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
62 static const int DAYS[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
63 static const int INT_HALF_BIT = 16;
64 static const int LOW_16BIT = 0xFFFF;
65 static const long long TOTAL_MAX_TICKS = DateTime::GetMaxValue().GetTicks();
67 DateTime::DateTime(void)
68 : __pDateTimeImpl(null)
70 SetValue(MIN_YEAR, MIN_MONTH, MIN_DAY, MIN_HOUR, MIN_MINUTE, MIN_SECOND);
73 DateTime::DateTime(const DateTime& value)
74 : __pDateTimeImpl(null)
79 DateTime::~DateTime(void)
84 DateTime::SetValue(const TimeSpan& value)
86 long long total = value.GetTicks();
87 SysTryReturn(NID_BASE, total >= MIN_TICK, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
88 "[%s] The value of the argument is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE));
90 SysTryReturn(NID_BASE, total <= TOTAL_MAX_TICKS, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
91 "[%s] The value of the argument is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE));
93 return ConvertTicksToDate(total, &__dateTime);
97 DateTime::SetValue(const DateTime& value)
99 __dateTime.year = value.__dateTime.year;
100 __dateTime.month = value.__dateTime.month;
101 __dateTime.day = value.__dateTime.day;
102 __dateTime.hour = value.__dateTime.hour;
103 __dateTime.minute = value.__dateTime.minute;
104 __dateTime.second = value.__dateTime.second;
108 DateTime::SetValue(int year, int month, int day, int hour, int minute, int second)
110 SysTryReturn(NID_BASE,
111 ((year >= MIN_YEAR && year <= _MAX_YEAR) &&
112 (month >= MIN_MONTH && month <= MAX_MONTH) &&
113 (hour >= MIN_HOUR && hour <= MAX_HOUR) &&
114 (minute >= MIN_MINUTE && minute <= MAX_MINUTE) &&
115 ((second & LOW_16BIT) >= MIN_SECOND && (second & LOW_16BIT) <= MAX_SECOND) &&
116 ((second >> INT_HALF_BIT) >= MIN_TICK && (second >> INT_HALF_BIT) <= MAX_TICK)),
117 E_OUT_OF_RANGE, E_OUT_OF_RANGE,
118 "[%s] One of the year(%d), month(%d), day(%d), hour(%d), minute(%d), second(%d) and tick(%d) is out of allowable range.",
119 GetErrorMessage(E_OUT_OF_RANGE), year, month, day, hour, minute, second & LOW_16BIT, second >> INT_HALF_BIT);
122 result r = GetDaysInMonth(year, month, daysInMonth);
123 SysTryReturn(NID_BASE, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
124 SysTryReturn(NID_BASE, (day >= MIN_DAY && day <= daysInMonth), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
125 ("[%s] day is out of allowable range."), GetErrorMessage(E_OUT_OF_RANGE));
127 __dateTime.year = year;
128 __dateTime.month = month;
129 __dateTime.day = day;
130 __dateTime.hour = hour;
131 __dateTime.minute = minute;
132 __dateTime.second = second;
137 DateTime::SetValue(int year, int month, int day, int hour, int minute, int second, int millisecond)
139 SysTryReturn(NID_BASE,
140 ((year >= MIN_YEAR && year <= _MAX_YEAR) &&
141 (month >= MIN_MONTH && month <= MAX_MONTH) &&
142 (hour >= MIN_HOUR && hour <= MAX_HOUR) &&
143 (minute >= MIN_MINUTE && minute <= MAX_MINUTE) &&
144 (second >= MIN_SECOND && second <= MAX_SECOND) &&
145 ((millisecond * TICKS_PER_MILLISECOND >= MIN_TICK) && (millisecond * TICKS_PER_MILLISECOND <= MAX_TICK))),
146 E_OUT_OF_RANGE, E_OUT_OF_RANGE,
147 "[%s] One of the year(%d), month(%d), day(%d), hour(%d), minute(%d), second(%d) and tick(%d) is out of allowable range.",
148 GetErrorMessage(E_OUT_OF_RANGE), year, month, day, hour, minute, second, millisecond * TICKS_PER_MILLISECOND);
151 result r = GetDaysInMonth(year, month, daysInMonth);
152 SysTryReturn(NID_BASE, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
153 SysTryReturn(NID_BASE, (day >= MIN_DAY && day <= daysInMonth), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
154 ("[%s] day is out of allowable range."), GetErrorMessage(E_OUT_OF_RANGE));
156 __dateTime.year = year;
157 __dateTime.month = month;
158 __dateTime.day = day;
159 __dateTime.hour = hour;
160 __dateTime.minute = minute;
161 __dateTime.second = ((millisecond * TICKS_PER_MILLISECOND) << INT_HALF_BIT) | second;
166 DateTime::SetValue(long long ticks)
168 return ConvertTicksToDate(ticks, &__dateTime);
172 DateTime::operator =(const DateTime& rhs)
183 DateTime::operator ==(const DateTime& rhs) const
185 return((__dateTime.year == rhs.__dateTime.year) && (__dateTime.month == rhs.__dateTime.month)
186 && (__dateTime.day == rhs.__dateTime.day) && (__dateTime.hour == rhs.__dateTime.hour) &&
187 (__dateTime.minute == rhs.__dateTime.minute) && (__dateTime.second == rhs.__dateTime.second));
191 DateTime::operator !=(const DateTime& rhs) const
193 return !(*this == rhs);
197 DateTime::operator <(const DateTime& rhs) const
199 if (__dateTime.year < rhs.__dateTime.year)
203 if (__dateTime.year > rhs.__dateTime.year)
207 if (__dateTime.month < rhs.__dateTime.month)
211 if (__dateTime.month > rhs.__dateTime.month)
215 if (__dateTime.day < rhs.__dateTime.day)
219 if (__dateTime.day > rhs.__dateTime.day)
223 if (__dateTime.hour < rhs.__dateTime.hour)
227 if (__dateTime.hour > rhs.__dateTime.hour)
231 if (__dateTime.minute < rhs.__dateTime.minute)
235 if (__dateTime.minute > rhs.__dateTime.minute)
239 if ((__dateTime.second & LOW_16BIT) < (rhs.__dateTime.second & LOW_16BIT))
243 if ((__dateTime.second & LOW_16BIT) > (rhs.__dateTime.second & LOW_16BIT))
247 if ((__dateTime.second >> INT_HALF_BIT) < (rhs.__dateTime.second >> INT_HALF_BIT))
256 DateTime::operator >(const DateTime& rhs) const
258 if (__dateTime.year > rhs.__dateTime.year)
262 if (__dateTime.year < rhs.__dateTime.year)
266 if (__dateTime.month > rhs.__dateTime.month)
270 if (__dateTime.month < rhs.__dateTime.month)
274 if (__dateTime.day > rhs.__dateTime.day)
278 if (__dateTime.day < rhs.__dateTime.day)
282 if (__dateTime.hour > rhs.__dateTime.hour)
286 if (__dateTime.hour < rhs.__dateTime.hour)
290 if (__dateTime.minute > rhs.__dateTime.minute)
294 if (__dateTime.minute < rhs.__dateTime.minute)
298 if ((__dateTime.second & LOW_16BIT) > (rhs.__dateTime.second & LOW_16BIT))
302 if ((__dateTime.second & LOW_16BIT) < (rhs.__dateTime.second & LOW_16BIT))
306 if ((__dateTime.second >> INT_HALF_BIT) > (rhs.__dateTime.second >> INT_HALF_BIT))
315 DateTime::operator <=(const DateTime& rhs) const
317 return ((*this == rhs) || (*this < rhs));
321 DateTime::operator >=(const DateTime& rhs) const
323 return ((*this == rhs) || (*this > rhs));
327 DateTime::Add(const TimeSpan& t)
329 result r = AddTicks(t.GetTicks());
330 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
336 DateTime::AddDays(int days)
338 long long ticks = static_cast< long long >(days) * NUM_OF_TICKS_IN_DAY;
340 result r = AddTicks(ticks);
341 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
347 DateTime::AddHours(int hours)
349 long long ticks = static_cast< long long >(hours) * NUM_OF_TICKS_IN_HOUR;
351 result r = AddTicks(ticks);
352 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
358 DateTime::AddMinutes(int minutes)
360 long long ticks = static_cast< long long >(minutes) * NUM_OF_TICKS_IN_MINUTE;
362 result r = AddTicks(ticks);
363 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
369 DateTime::AddMonths(int months)
374 tmp.__dateTime.year += months / MAX_MONTH; // Get the year to add
376 int tempMonth = tmp.__dateTime.month + months % MAX_MONTH;
377 if (tempMonth > MAX_MONTH) // Month was added and moved to next year
379 tmp.__dateTime.year++;
380 tmp.__dateTime.month = tempMonth - MAX_MONTH;
382 else if (tempMonth <= 0) // Month was subtracted and moved to previous year
384 tmp.__dateTime.year--;
385 tmp.__dateTime.month = MAX_MONTH + tempMonth;
387 else // Keep current year
389 tmp.__dateTime.month += months % MAX_MONTH;
392 // Check the days in Month
393 if (tmp.__dateTime.month != 2) // Current month is not Feb
395 if (tmp.__dateTime.day == 31) // Previous day is 31th
397 result r = SetValue(tmp.__dateTime.year, tmp.__dateTime.month, tmp.__dateTime.day);
398 if (IsFailed(r)) // Current month doesn't have 31th
400 tmp.__dateTime.day = 30; // Set day to 30th
404 else // Current month is Feb
406 if (tmp.__dateTime.day > 28) // Previous day is over 28th
408 if (tmp.IsLeapYear()) // Leap year
410 tmp.__dateTime.day = 29; // Set day to 29th
412 else // Not leap year
414 tmp.__dateTime.day = 28; // Set day to 28th
419 SysTryReturn(NID_BASE, (tmp <= DateTime::GetMaxValue()) && (tmp >= DateTime::GetMinValue()), E_OUT_OF_RANGE,
420 E_OUT_OF_RANGE, "[%s] The value of the argument is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE));
428 DateTime::AddSeconds(int seconds)
430 long long ticks = static_cast< long long >(seconds) * NUM_OF_TICKS_IN_SECOND;
432 result r = AddTicks(ticks);
433 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
439 DateTime::AddMilliseconds(long long milliseconds)
441 long long ticks = milliseconds * TICKS_PER_MILLISECOND;
443 result r = AddTicks(ticks);
444 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
450 DateTime::AddTicks(long long ticks)
452 long long total = ConvertDateToTicks(&__dateTime);
455 result r = ConvertTicksToDate(total, &__dateTime);
456 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
462 DateTime::AddYears(int years)
467 int sum = years + tmp.__dateTime.year;
469 SysTryReturn(NID_BASE, (sum >= MIN_YEAR && sum <= _MAX_YEAR), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
470 "[%s] The years(%d) + current year(%d) MUST be within the %d and %d (inclusive).",
471 GetErrorMessage(E_OUT_OF_RANGE), years, __dateTime.year, MIN_YEAR, _MAX_YEAR);
473 tmp.__dateTime.year = sum;
475 // Check the days in Month
476 if (tmp.__dateTime.month == 2) // Feb
478 if (tmp.__dateTime.day > 28)
480 if (tmp.IsLeapYear()) // Check the leap year
482 tmp.__dateTime.day = 29;
486 tmp.__dateTime.day = 28;
497 DateTime::Compare(const DateTime& dt1, const DateTime& dt2)
512 DateTime::CompareTo(const DateTime& value) const
514 return DateTime::Compare(*this, value);
518 DateTime::Equals(const Object& obj) const
520 const DateTime* pOther = dynamic_cast <const DateTime*>(&obj);
526 return (*this == *pOther);
530 DateTime::GetHashCode(void) const
532 TimeSpan t = GetTime();
533 int hash = t.GetHashCode();
534 return (hash ^ (hash >> INT_HALF_BIT));
538 DateTime::GetTimeOfDay(void) const
540 long long total = ConvertDateToSeconds(&__dateTime);
543 midnight.year = __dateTime.year;
544 midnight.month = __dateTime.month;
545 midnight.day = __dateTime.day;
546 midnight.hour = MIN_HOUR;
547 midnight.minute = MIN_MINUTE;
548 midnight.second = MIN_SECOND;
550 long long since = ConvertDateToSeconds(&midnight);
552 long long span = total - since;
554 return (TimeSpan(span * NUM_OF_TICKS_IN_SECOND));
558 DateTime::GetDaysInMonth(int year, int month, int& days)
560 const static int daysInMonth[] = { 0xFF, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
562 SysTryReturn(NID_BASE, (year >= MIN_YEAR && year <= _MAX_YEAR), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
563 "[%s] The year(%d) MUST be within the %d and %d (inclusive).", GetErrorMessage(E_OUT_OF_RANGE),
564 year, MIN_YEAR, _MAX_YEAR);
565 SysTryReturn(NID_BASE, (month >= MIN_MONTH && month <= MAX_MONTH), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
566 "[%s] The month(%d) MUST be within the %d and %d (inclusive).", GetErrorMessage(E_OUT_OF_RANGE),
567 month, MIN_MONTH, MAX_MONTH);
569 if (DateTime::IsLeapYear(year) && month == 2)
571 days = daysInMonth[month] + 1;
575 days = daysInMonth[month];
582 DateTime::Subtract(const TimeSpan& t)
585 long long total = ConvertDateToTicks(&__dateTime);
586 long long span = total - t.GetTicks();
588 SysTryReturn(NID_BASE, span >= MIN_TICK, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] The arguments contain invalid values.",
589 GetErrorMessage(E_OUT_OF_RANGE));
591 SysTryReturn(NID_BASE, span <= TOTAL_MAX_TICKS, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
592 "[%s] The value of the argument is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE));
594 result r = ConvertTicksToDate(span, &__dateTime);
595 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
601 DateTime::ToString(void) const
603 wchar_t date[] = L"01/01/1970 00:00:00";
605 swprintf(date, (sizeof(date) / sizeof(wchar_t)), L"%2d/%2d/%4d %2d:%2d:%2d",
606 __dateTime.month, __dateTime.day, __dateTime.year, __dateTime.hour, __dateTime.minute,
607 (__dateTime.second & LOW_16BIT));
609 if (__dateTime.month < 10)
614 if (__dateTime.day < 10)
619 if (__dateTime.year < 10)
625 else if (__dateTime.year < 100)
630 else if (__dateTime.year < 1000)
635 if (__dateTime.hour < 10)
640 if (__dateTime.minute < 10)
645 if ((__dateTime.second & LOW_16BIT) < 10)
654 DateTime::Parse(const String& str, DateTime& dt)
656 SysTryReturn(NID_BASE,
657 (str.GetLength() == 19
658 && str[2] == L'/' && str[5] == L'/' && str[10] == L' ' && str[13] == L':' && str[16] == L':'),
659 E_INVALID_FORMAT, E_INVALID_FORMAT, ("[%s] The str(%s) is not formatted like 'mm/dd/yyyy hh:mm:ss'."),
660 GetErrorMessage(E_INVALID_FORMAT), str.GetPointer());
662 std::unique_ptr<wchar_t []> pTmp(new (std::nothrow) wchar_t [5]);
663 SysTryReturn(NID_BASE, pTmp != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
664 GetErrorMessage(E_OUT_OF_MEMORY));
666 wchar_t* pMchar = const_cast< wchar_t* >(str.GetPointer());
669 wcsncpy(pTmp.get(), pMchar, 2);
672 int month = static_cast< int >(wcstol(pTmp.get(), null, 10));
675 wcsncpy(pTmp.get(), pMchar + 3, 2);
678 int day = static_cast< int >(wcstol(pTmp.get(), null, 10));
681 wcsncpy(pTmp.get(), pMchar + 6, 4);
684 int year = static_cast< int >(wcstol(pTmp.get(), null, 10));
687 wcsncpy(pTmp.get(), pMchar + 11, 2);
690 int hour = static_cast< int >(wcstol(pTmp.get(), null, 10));
693 wcsncpy(pTmp.get(), pMchar + 14, 2);
696 int minute = static_cast< int >(wcstol(pTmp.get(), null, 10));
699 wcsncpy(pTmp.get(), pMchar + 17, 2);
702 int sec = static_cast< int >(wcstol(pTmp.get(), null, 10));
704 // construct date time
706 result r = tmpDt.SetValue(year, month, day, hour, minute, sec);
707 SysTryReturnResult(NID_BASE, !IsFailed(r), r, ("[%s] Propagating."), GetErrorMessage(r));
715 DateTime::GetYear(void) const
717 return __dateTime.year;
721 DateTime::GetMonth(void) const
723 return __dateTime.month;
727 DateTime::GetDay(void) const
729 return __dateTime.day;
733 DateTime::GetHour(void) const
735 return __dateTime.hour;
739 DateTime::GetMinute(void) const
741 return __dateTime.minute;
745 DateTime::GetSecond(void) const
747 return (__dateTime.second & LOW_16BIT);
751 DateTime::GetMillisecond(void) const
753 return ((__dateTime.second >> INT_HALF_BIT) / TICKS_PER_MILLISECOND);
757 DateTime::GetTicks(void) const
759 return ConvertDateToTicks(&__dateTime);
763 DateTime::GetTicksPerSecond(void)
765 return NUM_OF_TICKS_IN_SECOND;
769 DateTime::GetTime(void) const
771 long long seconds = ConvertDateToSeconds(&__dateTime) - ConvertDateToSeconds(&(DateTime::GetMinValue().__dateTime));
773 return TimeSpan(seconds * NUM_OF_TICKS_IN_SECOND);
777 DateTime::GetMaxValue(void)
779 static DateTime maxValue(_MAX_YEAR, MAX_MONTH, MAX_DAY, MAX_HOUR, MAX_MINUTE, MAX_SECOND, MAX_TICK);
785 DateTime::GetMinValue(void)
787 static DateTime minValue(MIN_YEAR, MIN_MONTH, MIN_DAY, MIN_HOUR, MIN_MINUTE, MIN_SECOND, MIN_TICK);
793 DateTime::IsLeapYear(void) const
795 return DateTime::IsLeapYear(__dateTime.year);
799 DateTime::IsLeapYear(int year)
801 return year >= 0 && (!(year % 4) && ((year % 100) || !(year % 400)));
804 DateTime::DateTime(int year, int month, int day, int hour, int minute, int second, int tick)
805 : __pDateTimeImpl(null)
807 SetValue(year, month, day, hour, minute, (tick << INT_HALF_BIT) | second);
811 DateTime::ConvertTicksToDate(long long ticks, TmDateTime* pDateTime)
813 SysTryReturnResult(NID_BASE, (ticks >= MIN_TICK) && (ticks <= TOTAL_MAX_TICKS), E_OUT_OF_RANGE,
814 "[%s] The arguments (%lld) contain invalid values.", GetErrorMessage(E_OUT_OF_RANGE), ticks);
823 int totalDays = static_cast< int >(ticks / NUM_OF_TICKS_IN_DAY) + 1;
825 // Get a year and leapYear
826 int year = CountYears(totalDays);
829 bool leapYear = DateTime::IsLeapYear(year);
831 // Get days without year;
832 int tempDays = totalDays - CountDays(year);
835 if (tempDays == 0) // month = 0 , day = 0
844 for (; idx < 12; ++idx)
846 if ((DAYS_IN_LEAP_YEAR[idx] < tempDays) && (tempDays <= DAYS_IN_LEAP_YEAR[idx + 1]))
853 day = tempDays - DAYS_IN_LEAP_YEAR[idx];
859 for (; idx < 12; ++idx)
861 if ((DAYS[idx] < tempDays) && (tempDays <= DAYS[idx + 1]))
868 day = tempDays - DAYS[idx];
871 DateTime dt(year, month, day, 0, 0, 0, 0);
874 tempTicks = static_cast< int >(ticks - ConvertDateToTicks(&(dt.__dateTime)));
875 hour = tempTicks / NUM_OF_TICKS_IN_HOUR;
878 tempTicks -= hour * NUM_OF_TICKS_IN_HOUR;
879 minute = tempTicks / NUM_OF_TICKS_IN_MINUTE;
882 tempTicks -= minute * NUM_OF_TICKS_IN_MINUTE;
883 second = tempTicks / NUM_OF_TICKS_IN_SECOND;
886 tempTicks -= second * NUM_OF_TICKS_IN_SECOND;
887 second = ((tempTicks << INT_HALF_BIT) | second);
889 pDateTime->year = year;
890 pDateTime->month = month;
891 pDateTime->day = day;
892 pDateTime->hour = hour;
893 pDateTime->minute = minute;
894 pDateTime->second = second;
900 DateTime::ConvertDateToTicks(const TmDateTime* pDateTime) const
906 days = CountDays(pDateTime->year);
909 if (pDateTime->month != 0)
911 if (DateTime::IsLeapYear(pDateTime->year))
913 days += DAYS_IN_LEAP_YEAR[pDateTime->month - 1];
917 days += DAYS[pDateTime->month - 1];
922 days += pDateTime->day - 1;
925 ticks = days * NUM_OF_TICKS_IN_DAY;
928 ticks += pDateTime->hour * NUM_OF_TICKS_IN_HOUR;
931 ticks += pDateTime->minute * NUM_OF_TICKS_IN_MINUTE;
934 ticks += ((pDateTime->second) & LOW_16BIT) * NUM_OF_TICKS_IN_SECOND;
937 ticks += ((pDateTime->second) >> INT_HALF_BIT);
943 DateTime::ConvertSecondsToDate(long long seconds, TmDateTime* pDateTime)
945 long long ticks = seconds * NUM_OF_TICKS_IN_SECOND;
947 return ConvertTicksToDate(ticks, pDateTime);
951 DateTime::ConvertDateToSeconds(const TmDateTime* pDateTime) const
953 long long ticks = ConvertDateToTicks(pDateTime);
955 return ticks / NUM_OF_TICKS_IN_SECOND;