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 FBaseDateTime.cpp
19 * @brief This file contains implementation of DateTime class
24 #include <FBaseDateTime.h>
25 #include <FBaseResult.h>
26 #include <FBaseSysLog.h>
27 #include <unique_ptr.h>
29 namespace Tizen { namespace Base
48 NUM_OF_SEC_IN_DAY = 86400,
49 NUM_OF_SEC_IN_HOUR = 3600,
50 NUM_OF_SEC_IN_MINUTE = 60,
51 NUM_OF_TICKS_IN_DAY = 86400000LL,
52 NUM_OF_TICKS_IN_HOUR = 3600000LL,
53 NUM_OF_TICKS_IN_MINUTE = 60000LL,
54 NUM_OF_TICKS_IN_SECOND = 1000LL
57 static const int TICKS_PER_MILLISECOND = 1;
58 static const long SEC_IN_A_DAY = (24L * 60L * 60L);
59 static const long long MINIMUM_VALUE_IN_SEC = 86400LL;
60 static const int DAYS_IN_LEAP_YEAR[] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
61 static const int DAYS[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
62 static const int INT_HALF_BIT = 16;
63 static const int LOW_16BIT = 0xFFFF;
64 static const long long TOTAL_MAX_TICKS = DateTime::GetMaxValue().GetTicks();
66 DateTime::DateTime(void)
67 : __pDateTimeImpl(null)
69 SetValue(MIN_YEAR, MIN_MONTH, MIN_DAY, MIN_HOUR, MIN_MINUTE, MIN_SECOND);
72 DateTime::DateTime(const DateTime& value)
73 : __pDateTimeImpl(null)
78 DateTime::~DateTime(void)
83 DateTime::SetValue(const TimeSpan& value)
85 long long total = value.GetTicks();
86 SysTryReturn(NID_BASE, total >= MIN_TICK, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
87 "[%s] The value of the argument is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE));
89 SysTryReturn(NID_BASE, total <= TOTAL_MAX_TICKS, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
90 "[%s] The value of the argument is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE));
92 return ConvertTicksToDate(total, &__dateTime);
96 DateTime::SetValue(const DateTime& value)
98 __dateTime.year = value.__dateTime.year;
99 __dateTime.month = value.__dateTime.month;
100 __dateTime.day = value.__dateTime.day;
101 __dateTime.hour = value.__dateTime.hour;
102 __dateTime.minute = value.__dateTime.minute;
103 __dateTime.second = value.__dateTime.second;
107 DateTime::SetValue(int year, int month, int day, int hour, int minute, int second)
109 SysTryReturn(NID_BASE,
110 ((year >= MIN_YEAR && year <= _MAX_YEAR) &&
111 (month >= MIN_MONTH && month <= MAX_MONTH) &&
112 (hour >= MIN_HOUR && hour <= MAX_HOUR) &&
113 (minute >= MIN_MINUTE && minute <= MAX_MINUTE) &&
114 ((second & LOW_16BIT) >= MIN_SECOND && (second & LOW_16BIT) <= MAX_SECOND) &&
115 ((second >> INT_HALF_BIT) >= MIN_TICK && (second >> INT_HALF_BIT) <= MAX_TICK)),
116 E_OUT_OF_RANGE, E_OUT_OF_RANGE,
117 "[%s] One of the year(%d), month(%d), day(%d), hour(%d), minute(%d), second(%d) and tick(%d) is out of allowable range.",
118 GetErrorMessage(E_OUT_OF_RANGE), year, month, day, hour, minute, second & LOW_16BIT, second >> INT_HALF_BIT);
121 result r = GetDaysInMonth(year, month, daysInMonth);
122 SysTryReturn(NID_BASE, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
123 SysTryReturn(NID_BASE, (day >= MIN_DAY && day <= daysInMonth), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
124 ("[%s] day is out of allowable range."), GetErrorMessage(E_OUT_OF_RANGE));
126 __dateTime.year = year;
127 __dateTime.month = month;
128 __dateTime.day = day;
129 __dateTime.hour = hour;
130 __dateTime.minute = minute;
131 __dateTime.second = second;
136 DateTime::SetValue(int year, int month, int day, int hour, int minute, int second, int millisecond)
138 SysTryReturn(NID_BASE,
139 ((year >= MIN_YEAR && year <= _MAX_YEAR) &&
140 (month >= MIN_MONTH && month <= MAX_MONTH) &&
141 (hour >= MIN_HOUR && hour <= MAX_HOUR) &&
142 (minute >= MIN_MINUTE && minute <= MAX_MINUTE) &&
143 (second >= MIN_SECOND && second <= MAX_SECOND) &&
144 ((millisecond * TICKS_PER_MILLISECOND >= MIN_TICK) && (millisecond * TICKS_PER_MILLISECOND <= MAX_TICK))),
145 E_OUT_OF_RANGE, E_OUT_OF_RANGE,
146 "[%s] One of the year(%d), month(%d), day(%d), hour(%d), minute(%d), second(%d) and tick(%d) is out of allowable range.",
147 GetErrorMessage(E_OUT_OF_RANGE), year, month, day, hour, minute, second, millisecond * TICKS_PER_MILLISECOND);
150 result r = GetDaysInMonth(year, month, daysInMonth);
151 SysTryReturn(NID_BASE, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
152 SysTryReturn(NID_BASE, (day >= MIN_DAY && day <= daysInMonth), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
153 ("[%s] day is out of allowable range."), GetErrorMessage(E_OUT_OF_RANGE));
155 __dateTime.year = year;
156 __dateTime.month = month;
157 __dateTime.day = day;
158 __dateTime.hour = hour;
159 __dateTime.minute = minute;
160 __dateTime.second = ((millisecond * TICKS_PER_MILLISECOND) << INT_HALF_BIT) | second;
165 DateTime::SetValue(long long ticks)
167 return ConvertTicksToDate(ticks, &__dateTime);
171 DateTime::operator =(const DateTime& rhs)
182 DateTime::operator ==(const DateTime& rhs) const
184 return((__dateTime.year == rhs.__dateTime.year) && (__dateTime.month == rhs.__dateTime.month)
185 && (__dateTime.day == rhs.__dateTime.day) && (__dateTime.hour == rhs.__dateTime.hour) &&
186 (__dateTime.minute == rhs.__dateTime.minute) && (__dateTime.second == rhs.__dateTime.second));
190 DateTime::operator !=(const DateTime& rhs) const
192 return !(*this == rhs);
196 DateTime::operator <(const DateTime& rhs) const
198 if (__dateTime.year < rhs.__dateTime.year)
202 if (__dateTime.year > rhs.__dateTime.year)
206 if (__dateTime.month < rhs.__dateTime.month)
210 if (__dateTime.month > rhs.__dateTime.month)
214 if (__dateTime.day < rhs.__dateTime.day)
218 if (__dateTime.day > rhs.__dateTime.day)
222 if (__dateTime.hour < rhs.__dateTime.hour)
226 if (__dateTime.hour > rhs.__dateTime.hour)
230 if (__dateTime.minute < rhs.__dateTime.minute)
234 if (__dateTime.minute > rhs.__dateTime.minute)
238 if ((__dateTime.second & LOW_16BIT) < (rhs.__dateTime.second & LOW_16BIT))
242 if ((__dateTime.second & LOW_16BIT) > (rhs.__dateTime.second & LOW_16BIT))
246 if ((__dateTime.second >> INT_HALF_BIT) < (rhs.__dateTime.second >> INT_HALF_BIT))
255 DateTime::operator >(const DateTime& rhs) const
257 if (__dateTime.year > rhs.__dateTime.year)
261 if (__dateTime.year < rhs.__dateTime.year)
265 if (__dateTime.month > rhs.__dateTime.month)
269 if (__dateTime.month < rhs.__dateTime.month)
273 if (__dateTime.day > rhs.__dateTime.day)
277 if (__dateTime.day < rhs.__dateTime.day)
281 if (__dateTime.hour > rhs.__dateTime.hour)
285 if (__dateTime.hour < rhs.__dateTime.hour)
289 if (__dateTime.minute > rhs.__dateTime.minute)
293 if (__dateTime.minute < rhs.__dateTime.minute)
297 if ((__dateTime.second & LOW_16BIT) > (rhs.__dateTime.second & LOW_16BIT))
301 if ((__dateTime.second & LOW_16BIT) < (rhs.__dateTime.second & LOW_16BIT))
305 if ((__dateTime.second >> INT_HALF_BIT) > (rhs.__dateTime.second >> INT_HALF_BIT))
314 DateTime::operator <=(const DateTime& rhs) const
316 return ((*this == rhs) || (*this < rhs));
320 DateTime::operator >=(const DateTime& rhs) const
322 return ((*this == rhs) || (*this > rhs));
326 DateTime::Add(const TimeSpan& t)
328 result r = AddTicks(t.GetTicks());
329 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
335 DateTime::AddDays(int days)
337 long long ticks = static_cast< long long >(days) * NUM_OF_TICKS_IN_DAY;
339 result r = AddTicks(ticks);
340 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
346 DateTime::AddHours(int hours)
348 long long ticks = static_cast< long long >(hours) * NUM_OF_TICKS_IN_HOUR;
350 result r = AddTicks(ticks);
351 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
357 DateTime::AddMinutes(int minutes)
359 long long ticks = static_cast< long long >(minutes) * NUM_OF_TICKS_IN_MINUTE;
361 result r = AddTicks(ticks);
362 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
368 DateTime::AddMonths(int months)
373 tmp.__dateTime.year += months / MAX_MONTH; // Get the year to add
375 int tempMonth = tmp.__dateTime.month + months % MAX_MONTH;
376 if (tempMonth > MAX_MONTH) // Month was added and moved to next year
378 tmp.__dateTime.year++;
379 tmp.__dateTime.month = tempMonth - MAX_MONTH;
381 else if (tempMonth <= 0) // Month was subtracted and moved to previous year
383 tmp.__dateTime.year--;
384 tmp.__dateTime.month = MAX_MONTH + tempMonth;
386 else // Keep current year
388 tmp.__dateTime.month += months % MAX_MONTH;
391 // Check the days in Month
392 if (tmp.__dateTime.month != 2) // Current month is not Feb
394 if (tmp.__dateTime.day == 31) // Previous day is 31th
396 result r = SetValue(tmp.__dateTime.year, tmp.__dateTime.month, tmp.__dateTime.day);
397 if (IsFailed(r)) // Current month doesn't have 31th
399 tmp.__dateTime.day = 30; // Set day to 30th
403 else // Current month is Feb
405 if (tmp.__dateTime.day > 28) // Previous day is over 28th
407 if (tmp.IsLeapYear()) // Leap year
409 tmp.__dateTime.day = 29; // Set day to 29th
411 else // Not leap year
413 tmp.__dateTime.day = 28; // Set day to 28th
418 SysTryReturn(NID_BASE, (tmp <= DateTime::GetMaxValue()) && (tmp >= DateTime::GetMinValue()), E_OUT_OF_RANGE,
419 E_OUT_OF_RANGE, "[%s] The value of the argument is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE));
427 DateTime::AddSeconds(int seconds)
429 long long ticks = static_cast< long long >(seconds) * NUM_OF_TICKS_IN_SECOND;
431 result r = AddTicks(ticks);
432 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
438 DateTime::AddMilliseconds(long long milliseconds)
440 long long ticks = milliseconds * TICKS_PER_MILLISECOND;
442 result r = AddTicks(ticks);
443 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
449 DateTime::AddTicks(long long ticks)
451 long long total = ConvertDateToTicks(&__dateTime);
454 result r = ConvertTicksToDate(total, &__dateTime);
455 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
461 DateTime::AddYears(int years)
466 int sum = years + tmp.__dateTime.year;
468 SysTryReturn(NID_BASE, (sum >= MIN_YEAR && sum <= _MAX_YEAR), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
469 "[%s] The years(%d) + current year(%d) MUST be within the %d and %d (inclusive).",
470 GetErrorMessage(E_OUT_OF_RANGE), years, __dateTime.year, MIN_YEAR, _MAX_YEAR);
472 tmp.__dateTime.year = sum;
474 // Check the days in Month
475 if (tmp.__dateTime.month == 2) // Feb
477 if (tmp.__dateTime.day > 28)
479 if (tmp.IsLeapYear()) // Check the leap year
481 tmp.__dateTime.day = 29;
485 tmp.__dateTime.day = 28;
496 DateTime::Compare(const DateTime& dt1, const DateTime& dt2)
511 DateTime::CompareTo(const DateTime& value) const
513 return DateTime::Compare(*this, value);
517 DateTime::Equals(const Object& obj) const
519 const DateTime* pOther = dynamic_cast <const DateTime*>(&obj);
525 return (*this == *pOther);
529 DateTime::GetHashCode(void) const
531 TimeSpan t = GetTime();
532 int hash = t.GetHashCode();
533 return (hash ^ (hash >> INT_HALF_BIT));
537 DateTime::GetTimeOfDay(void) const
539 long long total = ConvertDateToSeconds(&__dateTime);
542 midnight.year = __dateTime.year;
543 midnight.month = __dateTime.month;
544 midnight.day = __dateTime.day;
545 midnight.hour = MIN_HOUR;
546 midnight.minute = MIN_MINUTE;
547 midnight.second = MIN_SECOND;
549 long long since = ConvertDateToSeconds(&midnight);
551 long long span = total - since;
553 return (TimeSpan(span * NUM_OF_TICKS_IN_SECOND));
557 DateTime::GetDaysInMonth(int year, int month, int& days)
559 const static int daysInMonth[] = { 0xFF, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
561 SysTryReturn(NID_BASE, (year >= MIN_YEAR && year <= _MAX_YEAR), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
562 "[%s] The year(%d) MUST be within the %d and %d (inclusive).", GetErrorMessage(E_OUT_OF_RANGE),
563 year, MIN_YEAR, _MAX_YEAR);
564 SysTryReturn(NID_BASE, (month >= MIN_MONTH && month <= MAX_MONTH), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
565 "[%s] The month(%d) MUST be within the %d and %d (inclusive).", GetErrorMessage(E_OUT_OF_RANGE),
566 month, MIN_MONTH, MAX_MONTH);
568 if (DateTime::IsLeapYear(year) && month == 2)
570 days = daysInMonth[month] + 1;
574 days = daysInMonth[month];
581 DateTime::Subtract(const TimeSpan& t)
584 long long total = ConvertDateToTicks(&__dateTime);
585 long long span = total - t.GetTicks();
587 SysTryReturn(NID_BASE, span >= MIN_TICK, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] The arguments contain invalid values.",
588 GetErrorMessage(E_OUT_OF_RANGE));
590 SysTryReturn(NID_BASE, span <= TOTAL_MAX_TICKS, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
591 "[%s] The value of the argument is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE));
593 result r = ConvertTicksToDate(span, &__dateTime);
594 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
600 DateTime::ToString(void) const
602 wchar_t date[] = L"01/01/1970 00:00:00";
604 swprintf(date, (sizeof(date) / sizeof(wchar_t)), L"%2d/%2d/%4d %2d:%2d:%2d",
605 __dateTime.month, __dateTime.day, __dateTime.year, __dateTime.hour, __dateTime.minute,
606 (__dateTime.second & LOW_16BIT));
608 if (__dateTime.month < 10)
613 if (__dateTime.day < 10)
618 if (__dateTime.year < 10)
624 else if (__dateTime.year < 100)
629 else if (__dateTime.year < 1000)
634 if (__dateTime.hour < 10)
639 if (__dateTime.minute < 10)
644 if ((__dateTime.second & LOW_16BIT) < 10)
653 DateTime::Parse(const String& str, DateTime& dt)
655 SysTryReturn(NID_BASE,
656 (str.GetLength() == 19
657 && str[2] == L'/' && str[5] == L'/' && str[10] == L' ' && str[13] == L':' && str[16] == L':'),
658 E_INVALID_FORMAT, E_INVALID_FORMAT, ("[%s] The str(%s) is not formatted like 'mm/dd/yyyy hh:mm:ss'."),
659 GetErrorMessage(E_INVALID_FORMAT), str.GetPointer());
661 std::unique_ptr<wchar_t []> pTmp(new (std::nothrow) wchar_t [5]);
662 SysTryReturn(NID_BASE, pTmp != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
663 GetErrorMessage(E_OUT_OF_MEMORY));
665 wchar_t* pMchar = const_cast< wchar_t* >(str.GetPointer());
668 wcsncpy(pTmp.get(), pMchar, 2);
671 int month = static_cast< int >(wcstol(pTmp.get(), null, 10));
674 wcsncpy(pTmp.get(), pMchar + 3, 2);
677 int day = static_cast< int >(wcstol(pTmp.get(), null, 10));
680 wcsncpy(pTmp.get(), pMchar + 6, 4);
683 int year = static_cast< int >(wcstol(pTmp.get(), null, 10));
686 wcsncpy(pTmp.get(), pMchar + 11, 2);
689 int hour = static_cast< int >(wcstol(pTmp.get(), null, 10));
692 wcsncpy(pTmp.get(), pMchar + 14, 2);
695 int minute = static_cast< int >(wcstol(pTmp.get(), null, 10));
698 wcsncpy(pTmp.get(), pMchar + 17, 2);
701 int sec = static_cast< int >(wcstol(pTmp.get(), null, 10));
703 // construct date time
705 result r = tmpDt.SetValue(year, month, day, hour, minute, sec);
706 SysTryReturnResult(NID_BASE, !IsFailed(r), r, ("[%s] Propagating."), GetErrorMessage(r));
714 DateTime::GetYear(void) const
716 return __dateTime.year;
720 DateTime::GetMonth(void) const
722 return __dateTime.month;
726 DateTime::GetDay(void) const
728 return __dateTime.day;
732 DateTime::GetHour(void) const
734 return __dateTime.hour;
738 DateTime::GetMinute(void) const
740 return __dateTime.minute;
744 DateTime::GetSecond(void) const
746 return (__dateTime.second & LOW_16BIT);
750 DateTime::GetMillisecond(void) const
752 return ((__dateTime.second >> INT_HALF_BIT) / TICKS_PER_MILLISECOND);
756 DateTime::GetTicks(void) const
758 return ConvertDateToTicks(&__dateTime);
762 DateTime::GetTicksPerSecond(void)
764 return NUM_OF_TICKS_IN_SECOND;
768 DateTime::GetTime(void) const
770 long long seconds = ConvertDateToSeconds(&__dateTime) - ConvertDateToSeconds(&(DateTime::GetMinValue().__dateTime));
772 return TimeSpan(seconds * NUM_OF_TICKS_IN_SECOND);
776 DateTime::GetMaxValue(void)
778 static DateTime maxValue(_MAX_YEAR, MAX_MONTH, MAX_DAY, MAX_HOUR, MAX_MINUTE, MAX_SECOND, MAX_TICK);
784 DateTime::GetMinValue(void)
786 static DateTime minValue(MIN_YEAR, MIN_MONTH, MIN_DAY, MIN_HOUR, MIN_MINUTE, MIN_SECOND, MIN_TICK);
792 DateTime::IsLeapYear(void) const
794 return DateTime::IsLeapYear(__dateTime.year);
798 DateTime::IsLeapYear(int year)
800 return year >= 0 && (!(year % 4) && ((year % 100) || !(year % 400)));
803 DateTime::DateTime(int year, int month, int day, int hour, int minute, int second, int tick)
804 : __pDateTimeImpl(null)
806 SetValue(year, month, day, hour, minute, (tick << INT_HALF_BIT) | second);
810 DateTime::ConvertTicksToDate(long long ticks, TmDateTime* pDateTime)
812 SysTryReturnResult(NID_BASE, (ticks >= MIN_TICK) && (ticks <= TOTAL_MAX_TICKS), E_OUT_OF_RANGE,
813 "[%s] The arguments (%lld) contain invalid values.", GetErrorMessage(E_OUT_OF_RANGE), ticks);
822 int totalDays = static_cast< int >(ticks / NUM_OF_TICKS_IN_DAY) + 1;
824 // Get a year and leapYear
825 int year = CountYears(totalDays);
828 bool leapYear = DateTime::IsLeapYear(year);
830 // Get days without year;
831 int tempDays = totalDays - CountDays(year);
834 if (tempDays == 0) // month = 0 , day = 0
843 for (; idx < 12; ++idx)
845 if ((DAYS_IN_LEAP_YEAR[idx] < tempDays) && (tempDays <= DAYS_IN_LEAP_YEAR[idx + 1]))
852 day = tempDays - DAYS_IN_LEAP_YEAR[idx];
858 for (; idx < 12; ++idx)
860 if ((DAYS[idx] < tempDays) && (tempDays <= DAYS[idx + 1]))
867 day = tempDays - DAYS[idx];
870 DateTime dt(year, month, day, 0, 0, 0, 0);
873 tempTicks = static_cast< int >(ticks - ConvertDateToTicks(&(dt.__dateTime)));
874 hour = tempTicks / NUM_OF_TICKS_IN_HOUR;
877 tempTicks -= hour * NUM_OF_TICKS_IN_HOUR;
878 minute = tempTicks / NUM_OF_TICKS_IN_MINUTE;
881 tempTicks -= minute * NUM_OF_TICKS_IN_MINUTE;
882 second = tempTicks / NUM_OF_TICKS_IN_SECOND;
885 tempTicks -= second * NUM_OF_TICKS_IN_SECOND;
886 second = ((tempTicks << INT_HALF_BIT) | second);
888 pDateTime->year = year;
889 pDateTime->month = month;
890 pDateTime->day = day;
891 pDateTime->hour = hour;
892 pDateTime->minute = minute;
893 pDateTime->second = second;
899 DateTime::ConvertDateToTicks(const TmDateTime* pDateTime) const
905 days = CountDays(pDateTime->year);
908 if (pDateTime->month != 0)
910 if (DateTime::IsLeapYear(pDateTime->year))
912 days += DAYS_IN_LEAP_YEAR[pDateTime->month - 1];
916 days += DAYS[pDateTime->month - 1];
921 days += pDateTime->day - 1;
924 ticks = days * NUM_OF_TICKS_IN_DAY;
927 ticks += pDateTime->hour * NUM_OF_TICKS_IN_HOUR;
930 ticks += pDateTime->minute * NUM_OF_TICKS_IN_MINUTE;
933 ticks += ((pDateTime->second) & LOW_16BIT) * NUM_OF_TICKS_IN_SECOND;
936 ticks += ((pDateTime->second) >> INT_HALF_BIT);
942 DateTime::ConvertSecondsToDate(long long seconds, TmDateTime* pDateTime)
944 long long ticks = seconds * NUM_OF_TICKS_IN_SECOND;
946 return ConvertTicksToDate(ticks, pDateTime);
950 DateTime::ConvertDateToSeconds(const TmDateTime* pDateTime) const
952 long long ticks = ConvertDateToTicks(pDateTime);
954 return ticks / NUM_OF_TICKS_IN_SECOND;