int DateTime::SetDateTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec) { return status_ = OleDateFromTm((WORD)nYear, (WORD)nMonth, (WORD)nDay, (WORD)nHour, (WORD)nMin, (WORD)nSec, dt_) ? valid : invalid; }
const DateTime& DateTime::operator=(const FILETIME& filetimeSrc) { // Assume UTC FILETIME, so convert to LOCALTIME FILETIME filetimeLocal; if (!FileTimeToLocalFileTime( &filetimeSrc, &filetimeLocal)) { status_ = invalid; } else { // Take advantage of SYSTEMTIME -> FILETIME conversion SYSTEMTIME systime; status_ = FileTimeToSystemTime(&filetimeLocal, &systime) ? valid : invalid; // At this point systime should always be valid, but... if (GetStatus() == valid) { status_ = OleDateFromTm(systime.wYear, systime.wMonth, systime.wDay, systime.wHour, systime.wMinute, systime.wSecond, dt_) ? valid : invalid; } } return *this; }
const DateTime& DateTime::operator=(const SYSTEMTIME& systimeSrc) { status_ = OleDateFromTm(systimeSrc.wYear, systimeSrc.wMonth, systimeSrc.wDay, systimeSrc.wHour, systimeSrc.wMinute, systimeSrc.wSecond, dt_) ? valid : invalid; return *this; }
DateTime::DateTime(const SYSTEMTIME& systimeSrc) { status_ = OleDateFromTm(systimeSrc.wYear, systimeSrc.wMonth, systimeSrc.wDay, systimeSrc.wHour, systimeSrc.wMinute, systimeSrc.wSecond, dt_) ? valid : invalid; }
STDMETHODIMP Profile::get_Birthday(DATE* pVal) { LONG yy, mm, dd; BOOL bOk = FALSE; try { WCHAR * pStrBirthdate = gSkypeQueue.RetrieveProperty(L"PROFILE", L"", L"BIRTHDAY"); if(swscanf_s(pStrBirthdate, L"%04d%02d%02d", & yy, & mm, &dd) == 3) { OleDateFromTm((WORD) yy, (WORD) mm, (WORD) dd, 0, 0, 0, * pVal); bOk = TRUE; } free(pStrBirthdate); return bOk; // 未入力の場合もエラーとしない。 //return bOk ? S_OK : AtlReportError(GetObjectCLSID(), L"Invalid birthday in user Profile", GUID_NULL, E_FAIL); } catch(const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
const DateTime& DateTime::operator=(const time_t& timeSrc) { // Convert time_t to struct tm tm *ptm = localtime(&timeSrc); if (ptm != NULL) { m_status = OleDateFromTm((WORD)(ptm->tm_year + 1900), (WORD)(ptm->tm_mon + 1), (WORD)ptm->tm_mday, (WORD)ptm->tm_hour, (WORD)ptm->tm_min, (WORD)ptm->tm_sec, m_dt) ? valid : invalid; } else { // Local time must have failed (timsSrc before 1/1/70 12am) } return *this; }
const DateTime& DateTime::operator=(const time_t& timeSrc) { // Convert time_t to struct tm struct tm ptm; int result = localtime_s(&ptm, &timeSrc); if (result == 0) { status_ = OleDateFromTm((WORD)(ptm.tm_year + 1900), (WORD)(ptm.tm_mon + 1), (WORD)ptm.tm_mday, (WORD)ptm.tm_hour, (WORD)ptm.tm_min, (WORD)ptm.tm_sec, dt_) ? valid : invalid; } else { // Local time must have failed (timsSrc before 1/1/70 12am) } return *this; }
DateTime::DateTime(time_t& timeSrc) { // Convert time_t to struct tm tm *ptm = localtime(&timeSrc); if (ptm != NULL) { m_status = OleDateFromTm((WORD)(ptm->tm_year + 1900), (WORD)(ptm->tm_mon + 1), (WORD)ptm->tm_mday, (WORD)ptm->tm_hour, (WORD)ptm->tm_min, (WORD)ptm->tm_sec, m_dt) ? valid : invalid; } else { // Local time must have failed (timsSrc before 1/1/70 12am) m_dt=0; SetStatus(invalid); } }
DateTime::DateTime(time_t& timeSrc) { // Convert time_t to struct tm struct tm ptm; int result = localtime_s(&ptm, &timeSrc); if (result == 0) { status_ = OleDateFromTm((WORD)(ptm.tm_year + 1900), (WORD)(ptm.tm_mon + 1), (WORD)ptm.tm_mday, (WORD)ptm.tm_hour, (WORD)ptm.tm_min, (WORD)ptm.tm_sec, dt_) ? valid : invalid; } else { // Local time must have failed (timsSrc before 1/1/70 12am) dt_=0; SetStatus(invalid); } }
int DateTime::SetDate(int nYear, int nMonth, int nDay) { return status_ = OleDateFromTm((WORD)nYear, (WORD)nMonth, (WORD)nDay, (WORD)0, (WORD)0, (WORD)0, dt_) ? valid : invalid; }