// SystemTime.cpp // // Revision Log // // Date Who SAR Notes // ========== === ======= ===================================== // 2001-10-29 mph Initial coding by Mark Henri of // MPH Software - markhenri@attbi.com // // #include "SystemTime.h" #include CSystemTime::CSystemTime() { Initialize(); } CSystemTime::CSystemTime(int y, int m, int d, int h, int mn, int s, int ms) { } CSystemTime::CSystemTime(const char* s) { Parse(s); } CSystemTime::CSystemTime(const std::string& s) { Parse(s.c_str()); } CSystemTime::CSystemTime(SYSTEMTIME& o) { wYear = o.wYear; wMonth = o.wMonth; wDayOfWeek = o.wDayOfWeek; wDay = o.wDay; wHour = o.wHour; wMinute = o.wMinute; wSecond = o.wSecond; wMilliseconds = o.wMilliseconds; } CSystemTime::CSystemTime(CSystemTime& o) { wYear = o.wYear; wMonth = o.wMonth; wDayOfWeek = o.wDayOfWeek; wDay = o.wDay; wHour = o.wHour; wMinute = o.wMinute; wSecond = o.wSecond; wMilliseconds = o.wMilliseconds; } CSystemTime::CSystemTime(FILETIME& ft) { Initialize(); SYSTEMTIME st; FileTimeToSystemTime(&ft, &st); *this = st; } CSystemTime& CSystemTime::operator = (FILETIME o) { Initialize(); SYSTEMTIME st; FileTimeToSystemTime(&o, &st); *this = st; return *this; } CSystemTime& CSystemTime::operator = (SYSTEMTIME o) { wYear = o.wYear; wMonth = o.wMonth; wDayOfWeek = o.wDayOfWeek; wDay = o.wDay; wHour = o.wHour; wMinute = o.wMinute; wSecond = o.wSecond; wMilliseconds = o.wMilliseconds; return *this; } CSystemTime& CSystemTime::operator=(CSystemTime& o) { wYear = o.wYear; wMonth = o.wMonth; wDayOfWeek = o.wDayOfWeek; wDay = o.wDay; wHour = o.wHour; wMinute = o.wMinute; wSecond = o.wSecond; wMilliseconds = o.wMilliseconds; return *this; } CSystemTime::~CSystemTime() { } CSystemTime::Initialize() { wYear = 0; wMonth = 0; wDayOfWeek = 0; wDay = 0; wHour = 0; wMinute = 0; wSecond = 0; wMilliseconds = 0; } CSystemTime& CSystemTime::operator = (const char* s) { return Parse(s); } CSystemTime& CSystemTime::operator = (const std::string& s) { return Parse(s.c_str()); } bool CSystemTime::operator ==(CSystemTime& o) { bool b = wYear == o.wYear && wMonth == o.wMonth && wDay == o.wDay && wHour == o.wHour && wMinute == o.wMinute && wSecond == o.wSecond && wMilliseconds == o.wMilliseconds; return b; } // format: yyyy-mm-dd hh:mm:ss.mmm // 01234567890123456789012 CSystemTime& CSystemTime::Parse(const char* s) { Initialize(); // set everything to zero int len = strlen(s); if (len < 4) return *this; wYear = atoi(s); if (len < 7) return *this; wMonth = atoi(&(s[5])); wDayOfWeek = 0; if (len < 10) return *this; wDay = atoi(&(s[8])); if (len < 13) return *this; wHour = atoi(&(s[11])); if (len < 16) return *this; wMinute = atoi(&(s[14])); if (len < 19) return *this; wSecond = atoi(&(s[17])); if (len < 23) return *this; wMilliseconds = atoi(&(s[20])); return *this; } rval_psz CSystemTime::c_str() { ostringstream os; os << *this; return os.str().c_str(); } void CSystemTime::ConvertToLocal() { TIME_ZONE_INFORMATION tzi; GetTimeZoneInformation(&tzi); SYSTEMTIME st1 = *this; if (! SystemTimeToTzSpecificLocalTime(&tzi, &st1, this)) { //CFormatMessage m(GetLastError()); //std::string s = m.GetMessage(); } } /* void CSystemTime::ConvertToUTC() { } */