CIMDateTime OperatingSystem::GetLocalDateTime(void) const { time_t currtime = time((time_t)0); struct tm tmBuffer; struct tm *loctime = localtime_r(&currtime, &tmBuffer); #if !defined(PEGASUS_OS_LSB) std::stringstream ss; ss << std::setfill('0'); ss << std::setw(4) << loctime->tm_year + 1900; ss << std::setw(2) << loctime->tm_mon + 1; ss << std::setw(2) << loctime->tm_mday; ss << std::setw(2) << loctime->tm_hour; ss << std::setw(2) << loctime->tm_min; ss << std::setw(2) << loctime->tm_sec; ss << '.'; ss << std::setw(6) << 0; ss << (loctime->tm_gmtoff < 0 ? "-" : "+"); ss << std::setw(3) << ::abs(loctime->tm_gmtoff / 60); // char* tmp = ss.str(); CIMDateTime localDateTime(ss.str().c_str()); // delete [] tmp; return localDateTime; #else CIMDateTime localDateTime; return (localDateTime); #endif }
bool ISO8601Parser::ParseDateTime(LPCTSTR pszTimestamp, std::wstring& strRemaining) { // convert to ptime using time input facet // http://stackoverflow.com/questions/2838524/use-boost-date-time-to-parse-and-create-http-dates //typedef boost::posix_time::wtime_input_facet time_input_facet; typedef boost::local_time::wlocal_time_input_facet time_input_facet; // note: inputFacet is not deleted here; it is done somewhere inside the stream classes time_input_facet* inputFacet = //new time_input_facet(L"%Y-%m-%dT%H:%M:%S%F%Q"); new time_input_facet(L"%Y-%m-%dT%H:%M:%S%F"); // note: we don't use // inputFacet->set_iso_extended_format(); // here, since it doesn't include the T divider std::wstringstream ss; ss.imbue(std::locale(ss.getloc(), inputFacet)); #ifdef _UNICODE ss.str(pszTimestamp); #else ss.str(std::wstring(CStringW(pszTimestamp).GetString())); #endif boost::local_time::local_date_time localDateTime( boost::local_time::local_sec_clock::local_time(boost::local_time::time_zone_ptr())); ss >> localDateTime; if (ss.fail()) return false; // convert to ptime m_dt = localDateTime.utc_time(); std::getline(ss, strRemaining); return true; }