#include "../config/pathan_config.h" /* * Copyright (c) 2001, DecisionSoft Limited All rights reserved. * Please see LICENSE.TXT for more information. */ #include "DateUtils.hpp" #include #include #include #include // for sprintf #include #include #include #include #include const int DateUtils::g_secondsPerMinute = 60; const int DateUtils::g_minutesPerHour = 60; const int DateUtils::g_hoursPerDay = 24; const int DateUtils::g_secondsPerHour = DateUtils::g_secondsPerMinute*DateUtils::g_minutesPerHour; const int DateUtils::g_secondsPerDay = DateUtils::g_secondsPerHour*DateUtils::g_hoursPerDay; void DateUtils::formatNumber(int value, int minDigits, XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer& buffer) { bool bIsNegative=false; if(value<0) { bIsNegative=true; value=-value; } XMLCh tmpBuff[19]; XERCES_CPP_NAMESPACE_QUALIFIER XMLString::binToText(value,tmpBuff,18,10); if(bIsNegative) buffer.append(XERCES_CPP_NAMESPACE_QUALIFIER chDash); for(int len=XERCES_CPP_NAMESPACE_QUALIFIER XMLString::stringLen(tmpBuff);lengetMemoryManager(); // We get the current time and adjust it to our timezone. We then set // this timezone in the Date object. time_t curDate=context->getCurrentTime(); // Note using localtime uses the tzset() function used by // DateUtils::getImplicitTimezone. This function and getImplicitTimezone // MUST get the same value in order for the correct time to be stored. struct tm* curLocalDate=localtime(&curDate); char szDate[256]; sprintf(szDate,"%04d-%02d-%02d",curLocalDate->tm_year+1900, curLocalDate->tm_mon+1, curLocalDate->tm_mday); // no need to add timezone, it's already compensated for in localtime // date.setTimezone(Timezone(XSDecimal(DateUtils::getImplicitTimezone(), context->getMemoryManager()))); return DatatypeFactory::STR2AT::createDate(memMgr, memMgr->getPooledString(szDate), context); } const ATDateTimeOrDerived* DateUtils::getCurrentDateTime(const DynamicContext* context) { XPath2MemoryManager* memMgr = context->getMemoryManager(); // We get the current time and adjust it to our timezone. We then set // this timezone in the DateTime object. time_t curDate=context->getCurrentTime(); // Note using localtime uses the tzset() function used by // DateUtils::getImplicitTimezone. This function and getImplicitTimezone // MUST get the same value in order for the correct time to be stored. struct tm* curLocalDate=localtime(&curDate); char szDate[256]; sprintf(szDate,"%04d-%02d-%02dT%02d:%02d:%02dZ", curLocalDate->tm_year+1900, curLocalDate->tm_mon+1, curLocalDate->tm_mday, curLocalDate->tm_hour, curLocalDate->tm_min, curLocalDate->tm_sec); // no need to add timezone, it's already compensated for in localtime // dateTime.setTimezone(Timezone(XSDecimal(DateUtils::getImplicitTimezone(), context->getMemoryManager()))); return DatatypeFactory::STR2AT::createDateTime(memMgr, memMgr->getPooledString(szDate), context); }