// //////////////////////////////////////////////////////////////////////////// TimeVal &TimeVal::AddMicroseconds(int usecs_to_add) { int secs_to_add = usecs_to_add / 1000000; int new_usec = tv_usec + (usecs_to_add % 1000000); if (new_usec >= 1000000) { secs_to_add += new_usec / 1000000; new_usec %= 1000000; } else if (new_usec < 0) { secs_to_add += -1 + (new_usec / 1000000); new_usec = 1000000 + (new_usec % 1000000); } if (secs_to_add) { try { AddSeconds(secs_to_add); } catch (const std::exception &except) { Rethrow(except, "Unable to add the requested number of microseconds " "(" + AnyToString(usecs_to_add) + "): " + std::string(except.what())); } } tv_usec = new_usec; return(*this); }
// // get frames per second // void GetFramesPerSecond(void) { clock_t now; float delta; GameTick(); // add to global counter CheckRespawn(); if (frames++ >= FRAME_RATE_SAMPLES) { now = clock(); delta = (now - last_time) / (float)CLOCKS_PER_SEC; AddTime((float)(now - last_time)); AddSeconds(delta); // tabulate data last_time = now; framerate = FRAME_RATE_SAMPLES / delta; frames = 0; } // end of the if } // end of the functino
void Timespan::SetValue(const unsigned int days, const unsigned int hours, const unsigned int minutes, const double seconds) { time_span_ = static_cast<double> (days); AddHours(hours); AddMinutes(minutes); AddSeconds(seconds); }
FX_BOOL CFX_DateTime::AddMilliseconds(int32_t iMilliseconds) { if (iMilliseconds == 0) { return FALSE; } iMilliseconds += m_DateTime.Time.sTime.millisecond; int32_t iSeconds = (int32_t)(iMilliseconds / g_FXMillisecondsPerSecond); iMilliseconds %= g_FXMillisecondsPerSecond; if (iMilliseconds < 0) { iSeconds--, iMilliseconds += g_FXMillisecondsPerSecond; } m_DateTime.Time.sTime.millisecond = (FX_WORD)iMilliseconds; if (iSeconds != 0) { AddSeconds(iSeconds); } return TRUE; }
void Duration::SetInfo(const ods::DurationInfo &info) { if (info_ == nullptr) info_ = new ods::DurationInfo(); info_->CopyFrom(info); /** <number:time-style style:name="N40"> <number:hours number:style="long"/> <number:text>:</number:text> <number:minutes number:style="long"/> </number:time-style> **/ /** enum class Order : quint8 { HOURS_MINUTES, HOURS_MINUTES_SECONDS }; **/ const auto order = info_->order(); if (order == ods::duration::Order::HOURS_MINUTES) { AddHours(); AddSeparator(0); AddMinutes(); } else if (order == ods::duration::Order::HOURS_MINUTES_SECONDS) { AddHours(); AddSeparator(0); AddMinutes(); AddSeparator(1); AddSeconds(); } QString s = info_->truncate_on_overflow() ? "true" : "false"; tag_->AttrSet(tag_->ns().number(), ods::style::kTruncateOnOverflow, s); }
//添加天数(在原定时间上进行修改) BOOL AddDays(CONST LPSYSTEMTIME lpSrcTime, LPSYSTEMTIME lpDestTime, int days) { return AddSeconds(lpSrcTime, lpDestTime, days * 86400); }
//添加小时数(在原定时间上进行修改) BOOL AddHours(CONST LPSYSTEMTIME lpSrcTime, LPSYSTEMTIME lpDestTime, int hours) { return AddSeconds(lpSrcTime, lpDestTime, hours * 3600); }
//为一个系统时间增加指定的分钟数,将会在原时间上做修改,而不是返回新的实例 //注意不要直接在SYSTEMTIME上修改,而是通过FileTime中转 BOOL AddMinutes(CONST LPSYSTEMTIME lpSrcTime, LPSYSTEMTIME lpDestTime, int minutes) { return AddSeconds(lpSrcTime, lpDestTime, minutes * 60); }