* @file FBaseDateTime.cpp
* @brief This file contains implementation of DateTime class
*/
-
#include <stdlib.h>
#include <wchar.h>
#include <FBaseDateTime.h>
{
SysTryReturn(NID_BASE,
((year >= MIN_YEAR && year <= _MAX_YEAR) &&
- (month >= MIN_MONTH && month <= MAX_MONTH) &&
- (hour >= MIN_HOUR && hour <= MAX_HOUR) &&
- (minute >= MIN_MINUTE && minute <= MAX_MINUTE) &&
- ((second & LOW_16BIT) >= MIN_SECOND && (second & LOW_16BIT) <= MAX_SECOND) &&
- ((second >> INT_HALF_BIT) >= MIN_TICK && (second >> INT_HALF_BIT) <= MAX_TICK)),
+ (month >= MIN_MONTH && month <= MAX_MONTH) &&
+ (hour >= MIN_HOUR && hour <= MAX_HOUR) &&
+ (minute >= MIN_MINUTE && minute <= MAX_MINUTE) &&
+ ((second & LOW_16BIT) >= MIN_SECOND && (second & LOW_16BIT) <= MAX_SECOND) &&
+ ((second >> INT_HALF_BIT) >= MIN_TICK && (second >> INT_HALF_BIT) <= MAX_TICK)),
E_OUT_OF_RANGE, E_OUT_OF_RANGE,
"[%s] One of the year(%d), month(%d), day(%d), hour(%d), minute(%d), second(%d) and tick(%d) is out of allowable range.",
GetErrorMessage(E_OUT_OF_RANGE), year, month, day, hour, minute, second & LOW_16BIT, second >> INT_HALF_BIT);
{
SysTryReturn(NID_BASE,
((year >= MIN_YEAR && year <= _MAX_YEAR) &&
- (month >= MIN_MONTH && month <= MAX_MONTH) &&
- (hour >= MIN_HOUR && hour <= MAX_HOUR) &&
- (minute >= MIN_MINUTE && minute <= MAX_MINUTE) &&
- (second >= MIN_SECOND && second <= MAX_SECOND) &&
- ((millisecond * TICKS_PER_MILLISECOND >= MIN_TICK) && (millisecond * TICKS_PER_MILLISECOND <= MAX_TICK))),
+ (month >= MIN_MONTH && month <= MAX_MONTH) &&
+ (hour >= MIN_HOUR && hour <= MAX_HOUR) &&
+ (minute >= MIN_MINUTE && minute <= MAX_MINUTE) &&
+ (second >= MIN_SECOND && second <= MAX_SECOND) &&
+ ((millisecond * TICKS_PER_MILLISECOND >= MIN_TICK) && (millisecond * TICKS_PER_MILLISECOND <= MAX_TICK))),
E_OUT_OF_RANGE, E_OUT_OF_RANGE,
"[%s] One of the year(%d), month(%d), day(%d), hour(%d), minute(%d), second(%d) and tick(%d) is out of allowable range.",
GetErrorMessage(E_OUT_OF_RANGE), year, month, day, hour, minute, second, millisecond * TICKS_PER_MILLISECOND);
DateTime::operator ==(const DateTime& rhs) const
{
return((__dateTime.year == rhs.__dateTime.year) && (__dateTime.month == rhs.__dateTime.month)
- && (__dateTime.day == rhs.__dateTime.day) && (__dateTime.hour == rhs.__dateTime.hour) &&
- (__dateTime.minute == rhs.__dateTime.minute) && (__dateTime.second == rhs.__dateTime.second));
+ && (__dateTime.day == rhs.__dateTime.day) && (__dateTime.hour == rhs.__dateTime.hour) &&
+ (__dateTime.minute == rhs.__dateTime.minute) && (__dateTime.second == rhs.__dateTime.second));
}
bool
tmp.__dateTime.year += months / MAX_MONTH; // Get the year to add
int tempMonth = tmp.__dateTime.month + months % MAX_MONTH;
- if (tempMonth > MAX_MONTH) // Month was added and moved to next year
+ if (tempMonth > MAX_MONTH) // Month was added and moved to next year
{
tmp.__dateTime.year++;
tmp.__dateTime.month = tempMonth - MAX_MONTH;
}
- else if (tempMonth <= 0) // Month was subtracted and moved to previous year
+ else if (tempMonth <= 0) // Month was subtracted and moved to previous year
{
tmp.__dateTime.year--;
tmp.__dateTime.month = MAX_MONTH + tempMonth;
}
- else // Keep current year
+ else // Keep current year
{
tmp.__dateTime.month += months % MAX_MONTH;
}
// Check the days in Month
if (tmp.__dateTime.month != 2) // Current month is not Feb
{
- if (tmp.__dateTime.day == 31) // Previous day is 31th
+ if (tmp.__dateTime.day == 31) // Previous day is 31th
{
result r = SetValue(tmp.__dateTime.year, tmp.__dateTime.month, tmp.__dateTime.day);
- if (IsFailed(r)) // Current month doesn't have 31th
+ if (IsFailed(r)) // Current month doesn't have 31th
{
- tmp.__dateTime.day = 30; // Set day to 30th
+ tmp.__dateTime.day = 30; // Set day to 30th
}
}
}
- else // Current month is Feb
+ else // Current month is Feb
{
- if (tmp.__dateTime.day > 28) // Previous day is over 28th
+ if (tmp.__dateTime.day > 28) // Previous day is over 28th
{
- if (tmp.IsLeapYear()) // Leap year
+ if (tmp.IsLeapYear()) // Leap year
{
- tmp.__dateTime.day = 29; // Set day to 29th
+ tmp.__dateTime.day = 29; // Set day to 29th
}
- else // Not leap year
+ else // Not leap year
{
- tmp.__dateTime.day = 28; // Set day to 28th
+ tmp.__dateTime.day = 28; // Set day to 28th
}
}
}
bool
DateTime::Equals(const Object& obj) const
{
- const DateTime* pOther = dynamic_cast <const DateTime*>(&obj);
+ const DateTime* pOther = dynamic_cast< const DateTime* >(&obj);
if (pOther == null)
{
return false;
wchar_t date[] = L"01/01/1970 00:00:00";
swprintf(date, (sizeof(date) / sizeof(wchar_t)), L"%2d/%2d/%4d %2d:%2d:%2d",
- __dateTime.month, __dateTime.day, __dateTime.year, __dateTime.hour, __dateTime.minute,
- (__dateTime.second & LOW_16BIT));
+ __dateTime.month, __dateTime.day, __dateTime.year, __dateTime.hour, __dateTime.minute,
+ (__dateTime.second & LOW_16BIT));
if (__dateTime.month < 10)
{
E_INVALID_FORMAT, E_INVALID_FORMAT, ("[%s] The str(%s) is not formatted like 'mm/dd/yyyy hh:mm:ss'."),
GetErrorMessage(E_INVALID_FORMAT), str.GetPointer());
- std::unique_ptr<wchar_t []> pTmp(new (std::nothrow) wchar_t [5]);
+ std::unique_ptr< wchar_t[] > pTmp(new (std::nothrow) wchar_t[5]);
SysTryReturn(NID_BASE, pTmp != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
GetErrorMessage(E_OUT_OF_MEMORY));
}
}} // Tizen::Base
-
-