String JMChattControl::GetDayOfWeekString(DateTime timeDate) { String strDayOfWeek=L""; int nDayOfWeek = GetDayOfWeek(timeDate); switch( nDayOfWeek ) { case 0 : strDayOfWeek = L"Sat"; break; case 1 : strDayOfWeek = L"Sun"; break; case 2 : strDayOfWeek = L"Mon"; break; case 3 : strDayOfWeek = L"Tue"; break; case 4 : strDayOfWeek = L"Wed"; break; case 5 : strDayOfWeek = L"Thu"; break; default : strDayOfWeek = L"Fri"; break; } return strDayOfWeek; }
void XTime::GetTime(XString8 &strTime) { int v=GetDayOfWeek(); strTime=WeekDay(v); v=GetDay(); if(v<10) strTime+=",0"; else strTime+=","; strTime+=v; strTime+=' '; //v=GetMonth(); strTime+=Month(GetMonth()); strTime+=' '; strTime+=GetYear(); strTime+=' '; if (this->GetHour()<10) strTime+='0'; strTime+=GetHour(); strTime+=':'; if (this->GetMinute()<10) strTime+='0'; strTime+=GetMinute(); strTime+=':'; if (this->GetSecond()<10) strTime+='0'; strTime+=GetSecond(); strTime+=" GMT"; }
static int diffday(long d1, long d2){ if ( d1 == d2 ){ return 0; } long big , small ; if( d1 > d2 ){ big = d1; small = d2; } else { big = d2; small = d1; } int gap = ( big - small )/DAY_SECONDS; long big_left = small + ( big - small )%DAY_SECONDS; if(GetDayOfWeek(big_left)!=GetDayOfWeek(small)){ gap ++; } return gap; }
std::string Time::GetDayOfWeekName () { switch (GetDayOfWeek()) { case 1: return "Sunday"; break; case 2: return "Monday"; break; case 3: return "Tuesday"; break; case 4: return "Wednesday"; break; case 5: return "Thursday"; break; case 6: return "Friday"; break; case 7: return "Saturday"; break; } return "day error"; }
/** * Return textual representation of day of week; */ char *DayOfWeek (unsigned int year, unsigned int month, unsigned int day) { static char DayOfWeekChar[10]; strcpy(DayOfWeekChar,""); switch (GetDayOfWeek(year, month, day)) { case 0: strcpy(DayOfWeekChar,"Sun"); break; case 1: strcpy(DayOfWeekChar,"Mon"); break; case 2: strcpy(DayOfWeekChar,"Tue"); break; case 3: strcpy(DayOfWeekChar,"Wed"); break; case 4: strcpy(DayOfWeekChar,"Thu"); break; case 5: strcpy(DayOfWeekChar,"Fri"); break; case 6: strcpy(DayOfWeekChar,"Sat"); break; } return DayOfWeekChar; }
char *OSDate (GSM_DateTime dt) { struct tm timeptr; static char retval[200],retval2[200]; #ifdef WIN32 setlocale(LC_ALL, ".OCP"); #endif timeptr.tm_yday = 0; /* FIXME */ timeptr.tm_isdst = -1; /* FIXME */ timeptr.tm_year = dt.Year - 1900; timeptr.tm_mon = dt.Month - 1; timeptr.tm_mday = dt.Day; timeptr.tm_hour = dt.Hour; timeptr.tm_min = dt.Minute; timeptr.tm_sec = dt.Second; timeptr.tm_wday = GetDayOfWeek(dt.Year, dt.Month, dt.Day); #ifdef HAVE_STRUCT_TM_TM_ZONE timeptr.tm_zone = NULL; #endif /* This is not Y2K safe */ strftime(retval2, 200, "%x", &timeptr); /* If don't have weekday name, include it */ strftime(retval, 200, "%A", &timeptr); if (strstr(retval2,retval)==NULL) { /* Check also for short name */ strftime(retval, 200, "%a", &timeptr); if (strstr(retval2,retval)==NULL) { strcat(retval2," ("); strcat(retval2,retval); strcat(retval2,")"); } } #ifdef WIN32 setlocale(LC_ALL, ".ACP"); #endif return retval2; }
int GetDayOfWeek() { return GetDayOfWeek(GetUnixTimestamp()); }
CString CSonTime::get_partV(char b) { CString c; char a[255]; int i; switch (b) { case 'A': { i = GetDayOfWeek(); switch (i) { case 1: c = "Sunday"; break; case 4: c.Format("%s %s","wday",unit_arr[15]); break; default: { c.Format("%s",m_pfnV(_itoa(i,a,10))); c = c.Right(c.GetLength()-3); c = "wday " + c; } } } break; case 'B': { i = GetMonth(); switch (i) { case 4: c.Format("%s %s","month",unit_arr[15]); break; default: { c.Format("%s",m_pfnV(_itoa(i,a,10))); c = c.Right(c.GetLength()-3); c = "month " + c; } } } break; case 'd': { i = GetDay(); c.Format("%s",m_pfnV(_itoa(i,a,10))); c = c.Right(c.GetLength()-3); if (i<11) c = "day mg " + c; else c = "day " + c; } break; case 'H': { c.Format("%s hour",m_pfnV(_itoa(GetHour(),a,10))); c = c.Right(c.GetLength()-3); } break; case 'M': { c.Format("%s minute",m_pfnV(_itoa(GetMinute(),a,10))); c = c.Right(c.GetLength()-3) ; } break; case 'S': { c.Format("%s second",m_pfnV(_itoa(GetSecond(),a,10))); c = c.Right(c.GetLength()-3) ; } break; case 'y': { c.Format("%s",m_pfnV(_itoa(GetYear()%100,a,10))); c = c.Right(c.GetLength()-3) ; c = "year " + c; } break; case 'Y': { c.Format("%s",m_pfnV(_itoa(GetYear(),a,10))); c = c.Right(c.GetLength()-3) ; c = "year " + c; } break; default: c = b; } return c; }
//-------------------------- GLOBAL FUNCTION ---------------------------------* int TrcPrint(WORD wLevel, LPCTSTR pszFormat, ...) /*>>>> print trace line with current time I wLevel: trace level I pszFormat: format string for wsprintf() Result E_TRC_OK E_TRC_NOT_INITIALIZED E_TRC_BAD_LEVEL E_TRC_NO_RESOURCE <<<<*/ { if (!s_bInitialized) { return E_TRC_NOT_INITIALIZED; } if (s_traceMode == noTrace) { // trace mode is disabled return E_TRC_OK; } if ((wLevel & s_wLevel) == 0) { // this level is not activated return E_TRC_OK; } if (pszFormat == NULL) { return E_TRC_NO_RESOURCE; } // print time and level... SYSTEMTIME tm; GetLocalTime(&tm); TCHAR szBuffer[512]; EnterCriticalSection(&s_csTrcFile); if (s_bNewLine) { // insert date and time if start of new line: if (s_wCurrDay != tm.wDay) { printTrc(_T("--------------------------------------------------------------\n")); _stprintf(szBuffer, _T("Current date: %s %04d-%02d-%02d\n"), GetDayOfWeek(tm.wDayOfWeek), (int) tm.wYear, (int) tm.wMonth, (int) tm.wDay); printTrc(szBuffer); s_wCurrDay = tm.wDay; } _stprintf(szBuffer, _T("%02d:%02d:%02d.%03d(%03d)|"), (int) tm.wHour, (int) tm.wMinute, (int) tm.wSecond, (int) tm.wMilliseconds, ::GetCurrentThreadId()); printTrc(szBuffer); printTrc(GetTrcLevelString(wLevel)); printTrc(_T("|")); s_bNewLine = FALSE; } // ... and actual message: va_list args; va_start(args, pszFormat); int nBuf; nBuf = _vstprintf(szBuffer, pszFormat, args); assert(nBuf < _countof(szBuffer)); va_end(args); printTrc(szBuffer); int len = _tcslen(szBuffer); if (len > 0) { if ( (szBuffer[len - 1] == _T('\n')) || (szBuffer[len - 1] == _T('\r'))) { s_bNewLine = TRUE; } } // check if max file size was reached: if ((s_hfTrc != NULL) && s_bNewLine && (s_uFileSize > 0)) { if ((UINT)(ftell(s_hfTrc) / 1000) > s_uFileSize) { fclose(s_hfTrc); _tremove(s_pszOldTrcFile); _trename(s_pszTraceFile, s_pszOldTrcFile); s_hfTrc = NULL; s_wCurrDay = 0; // force date line as first line in new file } } LeaveCriticalSection(&s_csTrcFile); return E_TRC_OK; }
tm GetNextSunday(tm start) { return AddDays(start, DAYS_IN_WEEK - GetDayOfWeek(start)); }
///////////////////////////////////////////////// // Date-Time int TTm::GetDaysSinceMonday() const { const int Days = GetDayOfWeek() - 1; if (Days < 0) { return 6; } // Sunday return Days; }
int GetFirstDOW() { int dow=GetDayOfWeek()-(GetDayOfYear() % 7)+21; while (dow>6) dow-=7; return dow; }