Exemple #1
0
/*----------------------------------------------------------------------------------------------
	Set this SilTime to the indicated variant time. Variant time is always in local time.
----------------------------------------------------------------------------------------------*/
void SilTime::SetToVarTime(double vtim)
{
    double dbl = vtim;

    // So that the arithmetic works even for negative dates, convert the
    // date to the _actual number of days_ since 0000h 12/30/1899.
    if (dbl < 0.0)
        dbl = 2.0 * ceil(dbl) - dbl;

    // Get the local time value.
    dbl = (dbl - kvtimJanuary1st1601) * kmsecPerDay;
    m_msec = g_tmm.ToUtc((int64)dbl);
}
Exemple #2
0
/*----------------------------------------------------------------------------------------------
	Set the value of this SilTime according to the information in psti.
----------------------------------------------------------------------------------------------*/
void SilTime::SetTimeInfo(const SilTimeInfo & sti, bool fUtc)
{
    int dyear = sti.year + FloorDiv(sti.ymon - 1, kmonPerYear) - kyearBase;
    int mon = ModPos(sti.ymon - 1, kmonPerYear);

    // Calculate the day number.
    int64 day = (int64)365 * dyear +
                FloorDiv(dyear, 4) - FloorDiv(dyear, 100) + FloorDiv(dyear, 400) +
                g_rgyday[IsLeapYear(dyear + kyearBase)][mon] + sti.mday - 1;

    m_msec = day * kmsecPerDay +
             sti.hour * (int64)kmsecPerHour + sti.min * (int64)kmsecPerMin +
             sti.sec * (int64)kmsecPerSec + sti.msec;

    if (!fUtc)
        m_msec = g_tmm.ToUtc(m_msec);
}
Exemple #3
0
/*----------------------------------------------------------------------------------------------
	Set the value of this SilTime according to the information in psti.
----------------------------------------------------------------------------------------------*/
void SilTime::SetTimeInfo(const SilTimeInfo & sti, bool fUtc)
{
	int dyear = sti.year + FloorDiv(sti.ymon - 1, kmonPerYear) - kyearBase;
	int mon = ModPos(sti.ymon - 1, kmonPerYear);

	// Calculate the day number.
	int64 day = (int64)365 * dyear +
		FloorDiv(dyear, 4) - FloorDiv(dyear, 100) + FloorDiv(dyear, 400) +
		g_rgyday[IsLeapYear(dyear + kyearBase)][mon] + sti.mday - 1;

	m_msec = day * kmsecPerDay +
		sti.hour * (int64)kmsecPerHour + sti.min * (int64)kmsecPerMin +
		sti.sec * (int64)kmsecPerSec + sti.msec;

#if WIN32
	if (!fUtc)
		m_msec = g_tmm.ToUtc(m_msec);
#else // WIN32
	if (!fUtc && (sti.year > 1970))
	{
		m_msec *= kfttPerMsec;
		m_msec /= kfttPerSec;
		m_msec -= SECS_1601_TO_1970;

		time_t t = m_msec;
		struct tm *tm_lcl;
		tm_lcl = localtime(&t);
		int64 bias = tm_lcl->tm_gmtoff;
		m_msec += bias;

		m_msec += SECS_1601_TO_1970;
		m_msec *= kfttPerSec;
		m_msec /= kfttPerMsec;
	}
#endif // WIN32
}