void Clock::Advance(__int64 dt) { m_us += dt; m_time += m_us / 1000000; m_us %= 1000000; _gmtime64_s(&m_date, &m_time); }
static std::tm millisToUTC (int64 millis) noexcept { #if JUCE_WINDOWS && JUCE_MINGW time_t now = (time_t) (millis / 1000); return *gmtime (&now); #elif JUCE_WINDOWS std::tm result; millis /= 1000; if (_gmtime64_s (&result, &millis) != 0) zerostruct (result); return result; #else std::tm result; time_t now = (time_t) (millis / 1000); if (gmtime_r (&now, &result) == nullptr) zerostruct (result); return result; #endif }
/*! \relates XsTimeStamp \brief Converts the timestamp into an XsUtcTime object \param utc The UTC time object to write the conversion result to */ void XsTimeStamp_toUtcTime(struct XsTimeStamp* thisPtr, struct XsUtcTime* utc) { struct tm tmUtc; #ifdef _WIN32 __time64_t t; t = (__time64_t)(thisPtr->m_msTime / 1000); if (_gmtime64_s(&tmUtc, &t)) { //in case of an error the result is an invalid XsUtctime utc->m_valid = 0; return; } #else time_t t; t = (time_t)(thisPtr->m_msTime / 1000); if (gmtime_r(&t, &tmUtc) == 0) { //in case of an error the result is an invalid XsUtctime utc->m_valid = 0; return; } #endif utc->m_day = tmUtc.tm_mday + 1; utc->m_hour = tmUtc.tm_hour; utc->m_minute = tmUtc.tm_min; utc->m_month = tmUtc.tm_mon + 1; utc->m_nano = (uint32_t)((thisPtr->m_msTime % 1000) * 1e6); utc->m_second = tmUtc.tm_sec; utc->m_year = tmUtc.tm_year + 1900; utc->m_valid = 1; }
void SG_time__decode(SG_context* pCtx,SG_int64 iTime, SG_time* pTime) { // iTime contains time in milliseconds since epoch in UTC. // convert this to a SG_time expressed in UTC. time_t t1 = iTime / MILLISECONDS_PER_SECOND; #if defined(MAC) || defined(LINUX) struct tm* ptm = gmtime(&t1); #endif #if defined(WINDOWS) struct tm tBuf; struct tm* ptm = &tBuf; (void)_gmtime64_s(&tBuf,&t1); #endif SG_NULLARGCHECK_RETURN(pTime); pTime->year = ptm->tm_year + 1900; pTime->month = ptm->tm_mon + 1; pTime->mday = ptm->tm_mday; pTime->hour = ptm->tm_hour; pTime->min = ptm->tm_min; pTime->sec = ptm->tm_sec; pTime->msec = (SG_uint32)(iTime % MILLISECONDS_PER_SECOND); pTime->wday = ptm->tm_wday; pTime->yday = ptm->tm_yday; pTime->offsetUTC = 0; }
struct tm DateTime::ToUTCTm() const { __time64_t t = ShrinkToTimeT(time_.time_value); struct tm utc_time; if (_gmtime64_s(&utc_time, &t)) { throw std::invalid_argument("failed to convert to utc time"); } return utc_time; }
void __cdecl sdlogtime() { char timebuf[26]; time_t ltime; struct tm gmt; time(<ime); _gmtime64_s(&gmt, <ime); asctime_s(timebuf, 26, &gmt); timebuf[24] = '\0'; // remove newline SDLOG(0, "===== %s =====\n", timebuf); }
bool TSecTm::GetTmStruct(const uint& AbsSec, struct tm& Tm) { const time_t TimeT = time_t(AbsSec); #if defined(GLib_MSC) return _gmtime64_s(&Tm, &TimeT) == 0; #elif defined(GLib_BCB) Tm=*gmtime(&TimeT); return true; #else return gmtime_r(&TimeT, &Tm) != NULL; #endif }
bool MCS_secondstodatetime(double p_seconds, MCDateTime& r_datetime) { __time64_t t_universal_time; t_universal_time = (__time64_t)(p_seconds + 0.5); struct tm t_universal_tm; _gmtime64_s(&t_universal_tm, &t_universal_time); tm_to_datetime(false, t_universal_tm, r_datetime); return true; }
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); }
void date_time::to_tm(const time_t& t, tm_type& tm) { if (t == NULL_TIME) throw std::invalid_argument("cannot convert null date and time to time structure"); #ifdef _WIN32 # ifdef _USE_32BIT_TIME_T _gmtime32_s(&tm, &t); # else _gmtime64_s(&tm, &t); # endif #else gmtime_r(&t, &tm); #endif }
std::string FormatHTTPDate(__int64* ltime) { struct tm t; if(ltime != NULL) { _gmtime64_s(&t, ltime); } else { // 传入空指针,则取当前时间. __int64 ltime_cur; _time64( <ime_cur ); _gmtime64_s(&t, <ime_cur); } char szTime[100] = {0}; // 格式化邮件时间 - Sun, 24 Aug 2008 22:43:45 GMT sprintf(szTime, "%s, %d %s %d %d:%d:%d GMT", week[t.tm_wday], t.tm_mday, month[t.tm_mon], t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec); return szTime; }
CStringA CCookie::MakeExpiresStr(__time64_t tmExpires) { ASSERT( tmExpires >= 0); if(tmExpires < 1) tmExpires = 1; tm t; ENSURE(_gmtime64_s(&t, &tmExpires) == 0); CStringA str; str.Format("%s, %02d-%s-%04d %02d:%02d:%02d GMT", s_short_week[t.tm_wday], t.tm_mday, s_short_month[t.tm_mon], t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec); return str; }
void FHTML5PlatformTime::UtcTime( int32& Year, int32& Month, int32& DayOfWeek, int32& Day, int32& Hour, int32& Min, int32& Sec, int32& MSec ) { time_t ltime; time(<ime); struct tm gmt; _gmtime64_s(&gmt, <ime); Year = gmt.tm_year + 1900; Month = gmt.tm_mon + 1; DayOfWeek = gmt.tm_wday; Day = gmt.tm_mday; Hour = gmt.tm_hour; Min = gmt.tm_min; Sec = gmt.tm_sec; MSec = 0; }
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; }
struct tm* CMSTime::GetGmtTm(struct tm* ptm) const { // Ensure ptm is valid assert( ptm != NULL ); if (ptm != NULL) { struct tm ptmTemp; errno_t err = _gmtime64_s(&ptmTemp, &m_time); // Be sure the call succeeded if(err != 0) { return NULL; } *ptm = ptmTemp; return ptm; } return NULL; }
void Logger::Impl::formatTime() { __time64_t seconds = time_.getTime(); struct tm tm_time; char buf[32] = {0}; #ifdef Q_OS_WIN32 _gmtime64_s(&tm_time, &seconds); int len = _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%4d-%02d-%02d %02d:%02d:%02d ", tm_time.tm_year + 1900, tm_time.tm_mon + 1, tm_time.tm_mday, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec); #elif defined Q_OS_LINUX gmtime_r(&seconds, &tm_time); int len = snprintf(buf, sizeof(buf), "%4d-%02d-%02d %02d:%02d:%02d ", tm_time.tm_year + 1900, tm_time.tm_mon + 1, tm_time.tm_mday, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec); #endif stream_ << T(buf, len); }
StringBuffer unixTimeToString(const unsigned long unixTime, const bool isUTC) { StringBuffer ret; struct tm sysTime; __time64_t tstamp = (__time64_t)unixTime; int err = _gmtime64_s(&sysTime, &tstamp); if (err) { LOG.error("error in _gmtime64_s (code %d)", err); return ret; } int year = sysTime.tm_year + 1900; // starting from 1900 int month = sysTime.tm_mon + 1; // range [0-11] ret.sprintf("%d%02d%02dT%02d%02d%02d", year, month, sysTime.tm_mday, sysTime.tm_hour, sysTime.tm_min, sysTime.tm_sec); if (isUTC) { ret.append("Z"); } return ret; }
/* * Wraps `gmtime` functionality for multiple platforms. This * converts a time value to a time structure in UTC. * * Returns 0 on success, -1 on failure. */ static int get_gmtime(NPY_TIME_T *ts, struct tm *tms) { char *func_name = "<unknown>"; #if defined(_WIN32) #if defined(_MSC_VER) && (_MSC_VER >= 1400) if (gmtime_s(tms, ts) != 0) { func_name = "gmtime_s"; goto fail; } #elif defined(__GNUC__) && defined(NPY_MINGW_USE_CUSTOM_MSVCR) if (_gmtime64_s(tms, ts) != 0) { func_name = "_gmtime64_s"; goto fail; } #else struct tm *tms_tmp; tms_tmp = gmtime(ts); if (tms_tmp == NULL) { func_name = "gmtime"; goto fail; } memcpy(tms, tms_tmp, sizeof(struct tm)); #endif #else if (gmtime_r(ts, tms) == NULL) { func_name = "gmtime_r"; goto fail; } #endif return 0; fail: PyErr_Format(PyExc_OSError, "Failed to use '%s' to convert " "to a UTC time", func_name); return -1; }
/* private routines */ static void xstrftime(struct archive_string *as, const char *fmt, time_t t) { /** like strftime(3) but for time_t objects */ struct tm *rt; #if defined(HAVE_GMTIME_R) || defined(HAVE__GMTIME64_S) struct tm timeHere; #endif char strtime[100]; size_t len; #ifdef HAVE_GMTIME_R if ((rt = gmtime_r(&t, &timeHere)) == NULL) return; #elif defined(HAVE__GMTIME64_S) _gmtime64_s(&timeHere, &t); #else if ((rt = gmtime(&t)) == NULL) return; #endif /* leave the hard yacker to our role model strftime() */ len = strftime(strtime, sizeof(strtime)-1, fmt, rt); archive_strncat(as, strtime, len); }
void Clock::Restore(Buffer& buffer) { m_time = buffer.ReadSigned64(); m_us = buffer.ReadSigned64(); _gmtime64_s(&m_date, &m_time); }
static __time64_t __cdecl _make__time64_t ( struct tm *tb, int ultflag ) { __time64_t tmptm1, tmptm2, tmptm3; struct tm tbtemp; long dstbias = 0; long timezone = 0; _VALIDATE_RETURN( ( tb != NULL ), EINVAL, ( ( __time64_t )( -1 ) ) ) /* * First, make sure tm_year is reasonably close to being in range. */ if ( ((tmptm1 = tb->tm_year) < _BASE_YEAR - 1) || (tmptm1 > _MAX_YEAR64 + 1) ) goto err_mktime; /* * Adjust month value so it is in the range 0 - 11. This is because * we don't know how many days are in months 12, 13, 14, etc. */ if ( (tb->tm_mon < 0) || (tb->tm_mon > 11) ) { tmptm1 += (tb->tm_mon / 12); if ( (tb->tm_mon %= 12) < 0 ) { tb->tm_mon += 12; tmptm1--; } /* * Make sure year count is still in range. */ if ( (tmptm1 < _BASE_YEAR - 1) || (tmptm1 > _MAX_YEAR64 + 1) ) goto err_mktime; } /***** HERE: tmptm1 holds number of elapsed years *****/ /* * Calculate days elapsed minus one, in the given year, to the given * month. Check for leap year and adjust if necessary. */ tmptm2 = _days[tb->tm_mon]; if ( _IS_LEAP_YEAR(tmptm1) && (tb->tm_mon > 1) ) tmptm2++; /* * Calculate elapsed days since base date (midnight, 1/1/70, UTC) * * * 365 days for each elapsed year since 1970, plus one more day for * each elapsed leap year. no danger of overflow because of the range * check (above) on tmptm1. */ tmptm3 = (tmptm1 - _BASE_YEAR) * 365 + _ELAPSED_LEAP_YEARS(tmptm1); /* * elapsed days to current month (still no possible overflow) */ tmptm3 += tmptm2; /* * elapsed days to current date. */ tmptm1 = tmptm3 + (tmptm2 = (__time64_t)(tb->tm_mday)); /***** HERE: tmptm1 holds number of elapsed days *****/ /* * Calculate elapsed hours since base date */ tmptm2 = tmptm1 * 24; tmptm1 = tmptm2 + (tmptm3 = (__time64_t)tb->tm_hour); /***** HERE: tmptm1 holds number of elapsed hours *****/ /* * Calculate elapsed minutes since base date */ tmptm2 = tmptm1 * 60; tmptm1 = tmptm2 + (tmptm3 = (__time64_t)tb->tm_min); /***** HERE: tmptm1 holds number of elapsed minutes *****/ /* * Calculate elapsed seconds since base date */ tmptm2 = tmptm1 * 60; tmptm1 = tmptm2 + (tmptm3 = (__time64_t)tb->tm_sec); /***** HERE: tmptm1 holds number of elapsed seconds *****/ if ( ultflag ) { /* * Adjust for timezone. No need to check for overflow since * localtime() will check its arg value */ __tzset(); _ERRCHECK(_get_dstbias(&dstbias)); _ERRCHECK(_get_timezone(&timezone)); tmptm1 += timezone; /* * Convert this second count back into a time block structure. * If localtime returns NULL, return an error. */ if ( _localtime64_s(&tbtemp, &tmptm1) != 0 ) goto err_mktime; /* * Now must compensate for DST. The ANSI rules are to use the * passed-in tm_isdst flag if it is non-negative. Otherwise, * compute if DST applies. Recall that tbtemp has the time without * DST compensation, but has set tm_isdst correctly. */ if ( (tb->tm_isdst > 0) || ((tb->tm_isdst < 0) && (tbtemp.tm_isdst > 0)) ) { tmptm1 += dstbias; if ( _localtime64_s(&tbtemp, &tmptm1) != 0 ) goto err_mktime; } } else { if ( _gmtime64_s(&tbtemp, &tmptm1) != 0) goto err_mktime; } /***** HERE: tmptm1 holds number of elapsed seconds, adjusted *****/ /***** for local time if requested *****/ *tb = tbtemp; return tmptm1; err_mktime: /* * All errors come to here */ errno = EINVAL; return (__time64_t)(-1); }
struct tm *wxGmtime_r(const time_t* t, struct tm* tm) { __time64_t t64 = *t; return _gmtime64_s(tm, &t64) == 0 ? tm : NULL; }
tm * __cdecl gmtime_r(const time_t *timer, tm *result) { __time64_t t64 = *timer; if (!_gmtime64_s(result, &t64)) return result; return 0; }
bool InsertDate(char * def, char * pBuf, size_t & index, size_t & filelength, size_t maxlength, apr_time_t date_svn) { // Search for first occurrence of def in the buffer, starting at index. if (!FindPlaceholder(def, pBuf, index, filelength)) { // No more matches found. return false; } // Format the text to insert at the placeholder __time64_t ttime; if (date_svn == USE_TIME_NOW) _time64(&ttime); else ttime = date_svn/1000000L; struct tm newtime; if (strstr(def, "UTC")) { if (_gmtime64_s(&newtime, &ttime)) return false; } else { if (_localtime64_s(&newtime, &ttime)) return false; } char destbuf[1024] = { 0 }; char * pBuild = pBuf + index; ptrdiff_t Expansion; if ((strcmp(def,DATEWFMTDEF) == 0) || (strcmp(def,NOWWFMTDEF) == 0) || (strcmp(def,LOCKWFMTDEF) == 0) || (strcmp(def,DATEWFMTDEFUTC) == 0) || (strcmp(def,NOWWFMTDEFUTC) == 0) || (strcmp(def,LOCKWFMTDEFUTC) == 0)) { // Format the date/time according to the supplied strftime format string char format[1024] = { 0 }; char * pStart = pBuf + index + strlen(def); char * pEnd = pStart; while (*pEnd != '$') { pEnd++; if (pEnd - pBuf >= (__int64)filelength) return false; // No terminator - malformed so give up. } if ((pEnd - pStart) > 1024) { return false; // Format specifier too big } SecureZeroMemory(format, sizeof(format)); memcpy(format,pStart,pEnd - pStart); // to avoid wcsftime aborting if the user specified an invalid time format, // we set a custom invalid parameter handler that does nothing at all: // that makes wcsftime do nothing and set errno to EINVAL. // we restore the invalid parameter handler right after _invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(_invalid_parameter_donothing); if (strftime(destbuf,1024,format,&newtime) == 0) { if (errno == EINVAL) strcpy_s(destbuf, "Invalid Time Format Specified"); } _set_invalid_parameter_handler(oldHandler); Expansion = strlen(destbuf) - (strlen(def) + pEnd - pStart + 1); } else { // Format the date/time in international format as yyyy/mm/dd hh:mm:ss sprintf_s(destbuf, "%04d/%02d/%02d %02d:%02d:%02d", newtime.tm_year + 1900, newtime.tm_mon + 1, newtime.tm_mday, newtime.tm_hour, newtime.tm_min, newtime.tm_sec); Expansion = strlen(destbuf) - strlen(def); } // Replace the def string with the actual commit date if (Expansion < 0) { memmove(pBuild, pBuild - Expansion, filelength - ((pBuild - Expansion) - pBuf)); } else if (Expansion > 0) { // Check for buffer overflow if (maxlength < Expansion + filelength) return false; memmove(pBuild + Expansion, pBuild, filelength - (pBuild - pBuf)); } memmove(pBuild, destbuf, strlen(destbuf)); filelength += Expansion; return true; }
bool InsertDateW(wchar_t* def, wchar_t* pBuf, size_t& index, size_t& filelength, size_t maxlength, __time64_t ttime) { // Search for first occurrence of def in the buffer, starting at index. if (!FindPlaceholderW(def, pBuf, index, filelength)) { // No more matches found. return false; } // Format the text to insert at the placeholder if (ttime == USE_TIME_NOW) _time64(&ttime); struct tm newtime; if (wcsstr(def, L"UTC")) { if (_gmtime64_s(&newtime, &ttime)) return false; } else { if (_localtime64_s(&newtime, &ttime)) return false; } wchar_t destbuf[1024]; wchar_t* pBuild = pBuf + index; ptrdiff_t Expansion; if ((wcscmp(def,TEXT(DATEWFMTDEF)) == 0) || (wcscmp(def,TEXT(NOWWFMTDEF)) == 0) || (wcscmp(def,TEXT(DATEWFMTDEFUTC)) == 0) || (wcscmp(def,TEXT(NOWWFMTDEFUTC)) == 0)) { // Format the date/time according to the supplied strftime format string wchar_t format[1024] = { 0 }; wchar_t* pStart = pBuf + index + wcslen(def); wchar_t* pEnd = pStart; while (*pEnd != '$') { ++pEnd; if (((__int64)(pEnd - pBuf))*((__int64)sizeof(wchar_t)) >= (__int64)filelength) return false; // No terminator - malformed so give up. } if ((pEnd - pStart) > 1024) return false; // Format specifier too big memcpy(format, pStart, (pEnd - pStart) * sizeof(wchar_t)); // to avoid wcsftime aborting if the user specified an invalid time format, // we set a custom invalid parameter handler that does nothing at all: // that makes wcsftime do nothing and set errno to EINVAL. // we restore the invalid parameter handler right after _invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(_invalid_parameter_donothing); if (wcsftime(destbuf,1024,format,&newtime) == 0) { if (errno == EINVAL) wcscpy_s(destbuf, L"Invalid Time Format Specified"); } _set_invalid_parameter_handler(oldHandler); Expansion = wcslen(destbuf) - (wcslen(def) + pEnd - pStart + 1); } else { // Format the date/time in international format as yyyy/mm/dd hh:mm:ss swprintf_s(destbuf, L"%04d/%02d/%02d %02d:%02d:%02d", newtime.tm_year + 1900, newtime.tm_mon + 1, newtime.tm_mday, newtime.tm_hour, newtime.tm_min, newtime.tm_sec); Expansion = wcslen(destbuf) - wcslen(def); } // Replace the def string with the actual commit date if (Expansion < 0) memmove(pBuild, pBuild - Expansion, (filelength - ((pBuild - Expansion) - pBuf) * sizeof(wchar_t))); else if (Expansion > 0) { // Check for buffer overflow if (maxlength < Expansion * sizeof(wchar_t) + filelength) return false; memmove(pBuild + Expansion, pBuild, (filelength - (pBuild - pBuf) * sizeof(wchar_t))); } memmove(pBuild, destbuf, wcslen(destbuf) * sizeof(wchar_t)); filelength += Expansion * sizeof(wchar_t); return true; }