long WINAPI DLLExport AddSeconds(LPRDATA rdPtr, long param1) { long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT); long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT); if(p1==-1) return -1; if(p1!=rdPtr->timestamp) { __time64_t timestamp=(unsigned)p1; tm *temptime=_localtime64(×tamp); if(temptime==0) return -1; temptime->tm_sec+=p2; temptime->tm_isdst=-1; timestamp=_mktime64(temptime); if(timestamp>4294967294 || timestamp==-1) return -1; rdPtr->datetime=*temptime; rdPtr->timestamp=p1; return (time_t)timestamp; } tm datetime; datetime=rdPtr->datetime; datetime.tm_sec+=p2; // datetime.tm_isdst=-1; __time64_t timestamp=_mktime64(&datetime); if(timestamp>4294967294 || timestamp==-1) return -1; rdPtr->datetime=datetime; rdPtr->timestamp=(time_t)timestamp; return (time_t)timestamp; }
long WINAPI DLLExport GetTimeStamp(LPRDATA rdPtr, long param1) { long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT); long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT); long p3=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT); long p4=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT); long p5=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT); long p6=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT); tm datetime; datetime.tm_year=p1-1900; datetime.tm_mon=p2-1; datetime.tm_mday=p3; datetime.tm_hour=p4; datetime.tm_min=p5; datetime.tm_sec=p6; datetime.tm_isdst=-1; datetime.tm_wday=0; datetime.tm_yday=0; __time64_t timestamp=_mktime64(&datetime); if(timestamp>4294967294 || timestamp==-1) return -1; rdPtr->datetime=datetime; rdPtr->timestamp=(time_t)timestamp; return (time_t)timestamp; }
DateTime::DateTime(int year, int month, int day, int hour, int min, int sec, int ms) { assert(year >= 1970); assert(month >= 1 && month <= 12); assert(day >= 1 && day <= 31); assert(hour >= 0 && hour <= 23); assert(min >= 0 && min <= 59); assert(sec >= 0 && sec <= 59); assert(ms >= 0 && ms <= 999); struct tm std_tm; std_tm.tm_year = year - 1900; std_tm.tm_mon = month - 1; std_tm.tm_mday = day; std_tm.tm_hour = hour; std_tm.tm_min = min; std_tm.tm_sec = sec; std_tm.tm_isdst = -1; time_t since_epoch = _mktime64(&std_tm); if (since_epoch == -1) { throw std::invalid_argument("failed to convert to DateTime"); } time_.time_value = ExpandTimeT(since_epoch) + ms; }
CMSTime::CMSTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int nDST) { #pragma warning (push) #pragma warning (disable: 4127) // conditional expression constant assert( nYear >= 1900 ); assert( nMonth >= 1 && nMonth <= 12 ); assert( nDay >= 1 && nDay <= 31 ); assert( nHour >= 0 && nHour <= 23 ); assert( nMin >= 0 && nMin <= 59 ); assert( nSec >= 0 && nSec <= 59 ); #pragma warning (pop) struct tm atm; atm.tm_sec = nSec; atm.tm_min = nMin; atm.tm_hour = nHour; atm.tm_mday = nDay; atm.tm_mon = nMonth - 1; // tm_mon is 0 based atm.tm_year = nYear - 1900; // tm_year is 1900 based atm.tm_isdst = nDST; m_time = _mktime64(&atm); assert(m_time != -1); // indicates an illegal input time /*if(m_time == -1) { AtlThrow(E_INVALIDARG); }*/ }
static int convert_time(FILETIME* time, __time64_t* result, __time64_t def) { SYSTEMTIME sys; FILETIME local; if (time->dwLowDateTime || time->dwHighDateTime) { if (!FileTimeToLocalFileTime(time, &local) || !FileTimeToSystemTime(&local, &sys)) { win32_maperr(GetLastError()); return 0; } else { struct tm stamp = {sys.wSecond, sys.wMinute, sys.wHour, sys.wDay, sys.wMonth - 1, sys.wYear - 1900, 0, 0, 0}; *result = _mktime64(&stamp); } } else { *result = def; } return 1; }
long WINAPI DLLExport GetMonthDiff(LPRDATA rdPtr, long param1) { long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT); long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT); if(p1==-1 || p2==-1) return -1; if(p1==p2) return 0; tm datetime; int mon1; if(p1!=rdPtr->timestamp) { __time64_t timestamp=(unsigned)p1; tm *temptime=_localtime64(×tamp); if(temptime==0) return -1; datetime=*temptime; mon1=temptime->tm_mon; } else { datetime=rdPtr->datetime; mon1=datetime.tm_mon; } int year2, mon2; if(p2!=rdPtr->timestamp) { __time64_t timestamp=(unsigned)p2; tm *temptime=_localtime64(×tamp); if(temptime==0) return -1; year2=temptime->tm_year; mon2=temptime->tm_mon; } else { year2=rdPtr->datetime.tm_year; mon2=rdPtr->datetime.tm_mon; } datetime.tm_year=year2; datetime.tm_mon=mon2; __time64_t timestamp1a=_mktime64(&datetime); if(timestamp1a==-1) // shouldn't happen return -1; if((unsigned)p1>(unsigned)p2) if(timestamp1a>=(__time64_t)(unsigned)p2) return (mon1-mon2+12)%12; else return (mon1-mon2+11)%12; else if(timestamp1a<=(__time64_t)(unsigned)p2) return (mon1-mon2-12)%12; else return (mon1-mon2-11)%12; }
CDealTime::CDealTime(UINT year,UINT month,UINT day,UINT hour,UINT min,UINT sec) { struct tm tmNow; tmNow.tm_year = year - 1900; tmNow.tm_mon = month; tmNow.tm_mday = day; tmNow.tm_hour = hour; tmNow.tm_min = min; tmNow.tm_sec = sec; m_time = _mktime64(&tmNow); }
__time64_t NXtimet32to64(__time32_t t32) { tm t; _localtime32_s(&t, &t32); // ERR __time64_t r = _mktime64(&t); if(r == -1) { R(-1, "mktime error"); return _time64(NULL); } return r; }
void Clock::Set(int Year, int Month, int Day, int Hour, int Min, int Sec) { memset(&m_date, 0, sizeof(m_date)); m_date.tm_year = Year; m_date.tm_mon = Month; m_date.tm_mday = Day; m_date.tm_hour = Hour; m_date.tm_min = Min; m_date.tm_sec = Sec; m_time = _mktime64(&m_date); _gmtime64_s(&m_date, &m_time); }
bool MCS_datetimetouniversal(MCDateTime& x_datetime) { struct tm t_local_datetime; datetime_to_tm(true, x_datetime, t_local_datetime); __time64_t t_universal_time; t_universal_time = _mktime64(&t_local_datetime); if (t_universal_time == -1) return false; struct tm t_universal_tm; _gmtime64_s(&t_universal_tm, &t_universal_time); tm_to_datetime(false, t_universal_tm, x_datetime); return true; }
CMSTime::CMSTime(WORD wDosDate, WORD wDosTime, int nDST) { struct tm atm; atm.tm_sec = (wDosTime & ~0xFFE0) << 1; atm.tm_min = (wDosTime & ~0xF800) >> 5; atm.tm_hour = wDosTime >> 11; atm.tm_mday = wDosDate & ~0xFFE0; atm.tm_mon = ((wDosDate & ~0xFE00) >> 5) - 1; atm.tm_year = (wDosDate >> 9) + 80; atm.tm_isdst = nDST; m_time = _mktime64(&atm); assert(m_time != -1); // indicates an illegal input time /*if(m_time == -1) AtlThrow(E_INVALIDARG);*/ }
void CDessertSystem::InitLuaData() { __time64_t now = _time64(nullptr); __time64_t tCurTime = m_BaseDataManager.GetLogoutTime(); __time64_t nextRfreshTime = tCurTime; tm curTime; _localtime64_s(&curTime, &now); curTime.tm_hour = 5; curTime.tm_min = 0; curTime.tm_sec = 0; nextRfreshTime = _mktime64(&curTime); ///判断登出时间到登陆时间的这段时间中是否已经刷新了相关的领取数据 if (RefreshJudgement::JudgeCrossed(tCurTime, nextRfreshTime)) { ResetData(); } }
__time64_t NXdostimeto64(__time32_t dostime) { tm t; memset(&t, 0, sizeof(tm)); t.tm_sec = 2 * (dostime & 0x1f); t.tm_min = (dostime >> 5) & 0x3f; t.tm_hour = (dostime >> 11) & 0x1f; t.tm_mday = (dostime >> 16) & 0x1f; t.tm_mon = ((dostime >> 21) & 0x0f) - 1; t.tm_year = ((dostime >> 25) & 0x7f) + 1980 - 1900; __time64_t r = _mktime64(&t); if(r == -1) { R(-1, "mktime error"); return _time64(NULL); } return r; }
MightyTime::MightyTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int nDST) { struct tm atm; atm.tm_sec = nSec; atm.tm_min = nMin; atm.tm_hour = nHour; //_ASSERTE(nDay >= 1 && nDay <= 31); atm.tm_mday = nDay; //_ASSERTE(nMonth >= 1 && nMonth <= 12); atm.tm_mon = nMonth - 1; // tm_mon is 0 based //_ASSERTE(nYear >= 1900); atm.tm_year = nYear - 1900; // tm_year is 1900 based atm.tm_isdst = nDST; m_time = _mktime64(&atm); //_ASSERTE(m_time != -1); // indicates an illegal input time if(m_time == -1) { //AtlThrow(E_INVALIDARG); ; } }
bool CMissionActiveness::InitDataMgr(void * pData) { if (pData != nullptr) m_dwMissionActiveness = static_cast<DWORD*>(pData); ///初始判断是否可以重置任务数据 __time64_t tCurTime = m_pBaseDataMgr.GetLogoutTime(); __time64_t nextRefreshTime = tCurTime; __time64_t now = _time64(nullptr); tm curTime; _localtime64_s(&curTime, &now); curTime.tm_hour = 5; curTime.tm_min = 0; curTime.tm_sec = 0; nextRefreshTime = _mktime64(&curTime); if (RefreshJudgement::JudgeCrossed(tCurTime, nextRefreshTime)) { m_bInitResetMissionActiveness = true; } return true; }
time_t __cdecl mktime(struct tm *t) { return (time_t)_mktime64(t); }
static inline time_t mktime(struct tm *_tm) { return _mktime64(_tm); }
long WINAPI DLLExport GetDayDiff(LPRDATA rdPtr, long param1) { long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT); long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT); if(p1==-1 || p2==-1) return -1; if(p1==p2) return 0; tm datetime1; if(p1!=rdPtr->timestamp) { __time64_t timestamp=(unsigned)p1; tm *temptime=_localtime64(×tamp); if(temptime==0) return -1; datetime1=*temptime; } else { datetime1=rdPtr->datetime; } tm datetime2; if(p2!=rdPtr->timestamp) { __time64_t timestamp=(unsigned)p2; tm *temptime=_localtime64(×tamp); if(temptime==0) return -1; datetime2=*temptime; } else { datetime2=rdPtr->datetime; } // move datetime1 into the same dst block as datetime2 // alter the hour instead of the isdst setting because a negative // isdst makes it set the isdst instead of alter the hour. datetime1.tm_hour += datetime2.tm_isdst - datetime1.tm_isdst; _mktime64(&datetime1); // prepare a datetime that is datetime1's time and datetime 2's date tm datetime1a = datetime1; datetime1a.tm_year=datetime2.tm_year; datetime1a.tm_mon=datetime2.tm_mon; datetime1a.tm_mday=datetime2.tm_mday; __time64_t timestamp1a=_mktime64(&datetime1a); if(timestamp1a==-1) // shouldn't happen return -1; if((unsigned)p1>(unsigned)p2) { if(timestamp1a>=(__time64_t)(unsigned)p2) { if(datetime1.tm_mday<datetime2.tm_mday) datetime1a.tm_mon++; datetime1a.tm_mday=datetime1.tm_mday; if(_mktime64(&datetime1a)==-1) return -1; // shouldn't happen return datetime1a.tm_yday-datetime2.tm_yday; } else { if(datetime1.tm_mday<=datetime2.tm_mday) datetime1a.tm_mon++; datetime1a.tm_mday=datetime1.tm_mday; if(_mktime64(&datetime1a)==-1) return -1; // shouldn't happen return datetime1a.tm_yday-datetime2.tm_yday-1; } } else { if(timestamp1a<=(__time64_t)(unsigned)p2) { if(datetime1.tm_mday>datetime2.tm_mday) datetime1a.tm_mon--; datetime1a.tm_mday=datetime1.tm_mday; if(_mktime64(&datetime1a)==-1) return -1; // shouldn't happen return datetime1a.tm_yday-datetime2.tm_yday; } else { if(datetime1.tm_mday>=datetime2.tm_mday) datetime1a.tm_mon--; datetime1a.tm_mday=datetime1.tm_mday; if(_mktime64(&datetime1a)==-1) return -1; // shouldn't happen return datetime1a.tm_yday-datetime2.tm_yday+1; } } }
void CLimitDungeonManager::UpdateSchedule() { mRoomMap.clear(); mScheduleMap.clear(); __time64_t todayTime = 0; _time64(&todayTime); const struct tm todayDate = *_localtime64(&todayTime); const Event emptyEvent = {Event::TypeNone, 0, 0, 0}; mScheduleMap.insert( std::make_pair(todayTime, emptyEvent)); typedef CGameResourceManager::LimitDungeonScriptMap ScriptMap; const ScriptMap& scriptMap = g_CGameResourceManager.GetLimitDungeonScriptMap(); // 091106 LUJ, 일정을 구성한다 for(ScriptMap::const_iterator scriptIter = scriptMap.begin(); scriptMap.end() != scriptIter; ++scriptIter) { const LimitDungeonScript& script = scriptIter->second; const BOOL isNoHomeMap(script.mHome.mMapType != mMapType); const BOOL isNoPlayMap(script.mMapType != mMapType); if(isNoPlayMap && isNoHomeMap) { continue; } // 091106 LUJ, 일정을 등록한다 for(LimitDungeonScript::DateList::const_iterator dateIter = script.mDateList.begin(); script.mDateList.end() != dateIter; ++dateIter) { const LimitDungeonScript::Date& date = *dateIter; const WORD dayOnWeek = 7; // 091106 LUJ: 시작 요일과 끝 요일 사이에 며칠 간격인지 나타내는 상수 테이블 // 행: 시작 요일(일~토), 열: 끝 요일(일~토) const int howManyDayBetweenDayOfWeek[][dayOnWeek] = { {0, 1, 2, 3, 4, 5, 6}, {6, 0, 1, 2, 3, 4, 5}, {5, 6, 0, 1, 2, 3, 4}, {4, 5, 6, 0, 1, 2, 3}, {3, 4, 5, 6, 0, 1, 2}, {2, 3, 4, 5, 6, 0, 1}, {1, 2, 3, 4, 5, 6, 0}, }; // 091106 LUJ, 컨텐츠가 시작될 시간을 얻는다 struct tm futureDate(todayDate); const int howManyDay = howManyDayBetweenDayOfWeek[todayDate.tm_wday][date.mDayOfWeek]; futureDate.tm_mday = futureDate.tm_mday + howManyDay; mktime(&futureDate); futureDate.tm_hour = date.mStartHour; futureDate.tm_min = date.mStartmMinute; futureDate.tm_sec = 0; __time64_t openTime = _mktime64(&futureDate); const BOOL isPassed(openTime < todayTime); if(isPassed) { const __time64_t remainTime = openTime + date.mPlayTime - todayTime; // 091106 LUJ, 시간이 지났지만, 진행 가능한 경우 즉시 연다. // 비정기적인 사건이므로 일정 관리에 넣지 않는다 if(0 < remainTime) { const Event openEvent = { Event::TypeOpenIlregulary, script.mMapType, script.mChannel, remainTime}; CloseRoom( openEvent); OpenRoom( openEvent); const Event closeEvent = { Event::TypeCloseIlregulary, script.mMapType, script.mChannel, 0}; mScheduleMap.insert( std::make_pair(todayTime + remainTime, closeEvent)); } openTime = openTime + GetSecondForOneWeek(); } const Event openEvent = { Event::TypeOpen, script.mMapType, script.mChannel, date.mPlayTime}; const Event closeEvent = { Event::TypeClose, script.mMapType, script.mChannel, 0}; const __time64_t closeTime = openTime + date.mPlayTime; mScheduleMap.insert( std::make_pair(openTime, openEvent)); mScheduleMap.insert( std::make_pair(closeTime, closeEvent)); } } }
//----------------------------------------------------------------------------- // 轉型運算子 C_NTime::operator __int64 () const { struct tm sTime = *this; return _mktime64(&sTime); }
bool CMallManager::JudgementRefresh(const STimeData& time) { if (IsFristOpen()) return true; if (nullptr == m_pVecRefreshClock) return false; tm tsLogin, tsLastRefresh; __time64_t tLogin = *((__time64_t*)time.m_LoginTime); _localtime64_s(&tsLogin, &tLogin); __time64_t tLastRefresh = *((__time64_t*)m_pMallData->m_LastRefreshTime); _localtime64_s(&tsLastRefresh, &tLastRefresh); DWORD lastRefreshClock = tsLastRefresh.tm_hour; DWORD curClock = tsLogin.tm_hour; DWORD dwLastClockIndex = 0; int maxIndex = m_pVecRefreshClock->size() - 1; //获取上次刷新钟点的索引// for (int i = 0; i <= maxIndex; ++i) { if ((*m_pVecRefreshClock)[i] == lastRefreshClock) { dwLastClockIndex = i; break; } } bool bTomorrowRefresh = false; //当前时间(hour)大于等于最大刷新时间,即为明日刷新// if (curClock >= (*m_pVecRefreshClock)[maxIndex]) { m_dwNextClockIndex = 0; m_pMallData->m_dwNextRefreshTime = (*m_pVecRefreshClock)[0] + 24; ///<加上24表示到明日刷新// bTomorrowRefresh = true; } else { //判断下次刷新的时间点// for (int i = 0; i <= maxIndex; ++i) { if ((*m_pVecRefreshClock)[i] > curClock) { m_dwNextClockIndex = i; m_pMallData->m_dwNextRefreshTime = (*m_pVecRefreshClock)[i]; break; } } } int dayInterval = Days_Distance(tLogin, tLastRefresh); //当前登入的时间与上次刷新时间大于一天 则表示当前需要刷新(商城每日至少刷新一次)购买刷新的次数归0 if (dayInterval >= 1) { m_pMallData->m_dwRefreshedCount = 0; return true; } /// 判断是否重置刷新次数 __time64_t tLogout = *((__time64_t*)time.m_LogoutTime); __time64_t nextRefreshTime = tLogout; __time64_t now = _time64(nullptr); tm curTime; _localtime64_s(&curTime, &now); curTime.tm_hour = 5; curTime.tm_min = 0; curTime.tm_sec = 0; nextRefreshTime = _mktime64(&curTime); if (RefreshJudgement::JudgeCrossed(tLogout, nextRefreshTime)) { m_pMallData->m_dwRefreshedCount = 0; } //精度到天的两个时间点的判断 大于0表示两个时间点至少隔天了// int result = CompareTimeOfYear(tsLogin, tsLastRefresh); ///<理论上的上次刷新索引 m_dwCurClockIndex = m_dwNextClockIndex == 0 ? maxIndex : m_dwNextClockIndex - 1; if (result > 0) { //每日刷新时间点大于1个// if (maxIndex > 1) { //上次刷新的时间小于最晚刷新时间,则需要刷新// if (dwLastClockIndex < maxIndex) return true; //当前时间大于最早刷新时间,则需要刷新// if (curClock >= (*m_pVecRefreshClock)[0]) return true; } else //每日只需要刷新一次// { //上次刷新的时间小于刷新点时间或者当前时间大于刷新点时间,则需要刷新// if (lastRefreshClock < (*m_pVecRefreshClock)[0] || curClock >= (*m_pVecRefreshClock)[0]) return true; } } else if (result == 0) //上次刷新时间与当前登录时间在同一天// { //每日刷新时间点大于1个// if (maxIndex > 1) { //上次游戏刷新时间点小于理论上的上次刷新时间点则刷新// if (dwLastClockIndex < m_dwCurClockIndex) return true; } else { //当前时间超过或等于刷新时间点,则需要刷新// if (lastRefreshClock < (*m_pVecRefreshClock)[0] && curClock >= (*m_pVecRefreshClock)[0]) return true; } } return false; }
time_t __cdecl mktime(struct tm *_Tm) { return _mktime64(_Tm); }
uint64 XlMakeFileTime(struct tm* local) { return _mktime64(local); }