void TimeF::update() { const t_longf elapsed(M_Running == m_mode ? m_timer->time_s() : m_lastModeChangeTime); const t_longf elapsedTimef(m_secondsPerCycle > 0.f ? elapsed / m_secondsPerCycle : 0.f); m_timef[1] = _frac(m_timef[0] + elapsedTimef + m_offset); m_time[1] = fToSeconds(elapsedTimef + m_offset) + static_cast<t_longf>(m_time[0]); }
const t_aTime makeTime( t_julianDay julianDate , const short GMTOffset) { assert(julianDate >= 0.0); julianDate += 0.5; const int z = _int(julianDate); const t_longf f = _frac(julianDate); long int a(z); // julian if(z >= 2299161) // gregorian { const int g = _int((z - 1867216.25) / 36524.25); a = z + 1 + g - _int(g / 4); } const int b = _int(a + 1524); const int c = _int((b - 122.1) / 365.25); const int d = _int(365.25 * c); const int e = _int((b - d) / 30.600001); const short day = static_cast<short>(b - d - _int(30.600001 * e)); const short month = static_cast<short>(e < 14 ? e - 1 : e - 13); const short year = static_cast<short>(month > 2 ? c - 4716 : c - 4715); const t_longf h = f * 24.0; const t_longf m = _frac(h) * 60.0; const t_longf s = _frac(m) * 60.0001; const short hour = _short(h); const short minute = _short(m); const short second = _short(s); return t_aTime(year, month, day, hour, minute, second, GMTOffset); }
const time_t TimeF::sett( const time_t &time , const bool forceUpdate) { time_t t = time - utcOffset(); m_time[0] = t; m_time[2] = m_time[0]; m_timef[0] = _frac(secondsTof(t)); m_timef[2] = m_timef[0]; m_offset = 0; reset(forceUpdate); return gett(); }
const t_longf TimeF::setf( t_longf timef , const bool forceUpdate) { timef = _frac(timef); if(1.f == timef) timef = 0.f; m_timef[0] = timef; m_timef[2] = m_timef[0]; m_offset = 0; const time_t seconds(fToSeconds(timef)); #ifdef __GNUC__ struct tm lcl(*localtime(&m_time[1])); #else // __GNUC__ struct tm lcl; localtime_s(&lcl, &m_time[1]); #endif // __GNUC__ lcl.tm_hour = seconds / 3600; lcl.tm_min = seconds % 3600 / 60; lcl.tm_sec = seconds % 60; time_t mt = mktime(&lcl); if(mt == -1) m_time[0] = m_time[2] = 0; else m_time[0] = m_time[2] = mktime(&lcl) - utcOffset(); reset(forceUpdate); return getf(); }