예제 #1
0
// Convert the OsDateTimeBase value to an OsTime value
// The OsTime value is relative to when the system was booted.
OsStatus OsDateTimeLinux::cvtToTimeSinceBoot(OsTime& rTime) const
{
   unsigned long curTimeAsSecsSinceBoot;
   time_t        curTimeAsTimeT;
   struct tm     thisTime;
   long          thisTimeAsSecsSinceBoot;
   time_t        thisTimeAsTimeT;

   // convert "this" OsDateTime to a time_t representation
   thisTime.tm_year = mYear - 1900;
   thisTime.tm_mon  = mMonth;
   thisTime.tm_mday = mDay;
   thisTime.tm_hour = mHour;
   thisTime.tm_min  = mMinute;
   thisTime.tm_sec  = mSecond;
   thisTimeAsTimeT  = mktime(&thisTime);
   assert(thisTimeAsTimeT >= 0);

   // get the current time as a time_t
   curTimeAsTimeT   = time(NULL);
   assert(curTimeAsTimeT >= 0);

   // get the current time as seconds since boot
   curTimeAsSecsSinceBoot = (unsigned long)secondsSinceBoot();

   // convert "this" time to seconds since boot
   thisTimeAsSecsSinceBoot = (thisTimeAsTimeT - curTimeAsTimeT) +
                             curTimeAsSecsSinceBoot;

   OsTime deltaOsTime(thisTimeAsSecsSinceBoot, 0);
   rTime = deltaOsTime;

   return OS_SUCCESS;
}
예제 #2
0
// Convert the OsDateTimeBase value to an OsTime value
// The OsTime value is relative to when the system was booted.
OsStatus OsDateTimeWnt::cvtToTimeSinceBoot(OsTime& rTime) const
{
   UtlBoolean     ntRes;

   FILETIME   bootFileTime;      // boot time in various representations
   int64_t    bootTime_i64;

   FILETIME   thisFileTime;      // this time in various representations
   SYSTEMTIME thisSysTime;
   int64_t    thisTime_i64;

   int64_t    deltaTime_i64;     // (this time - boot time) in various
   int64_t    deltaSecs_i64;     //  representations
   int64_t    deltaUsecs_i64;

   // get the system boot time as a 64-bit integer recording the number of
   //  100-nanosecond intervals since January 1, 1601
   GetSystemTimeAsFileTime(&bootFileTime);          // get as FILETIME
   bootTime_i64 = (((int64_t)bootFileTime.dwHighDateTime) << 32) +
                  bootFileTime.dwLowDateTime;       // convert to int64_t

   // convert this OsDateTime object to a 64-bit integer
   thisSysTime.wYear         = mYear;               // represent as SYSTEMTIME
   thisSysTime.wMonth        = mMonth+1;  // because we subtracted previously(just like vxw)
   thisSysTime.wDay          = mDay;
   thisSysTime.wHour         = mHour;
   thisSysTime.wMinute       = mMinute;
   thisSysTime.wSecond       = mSecond;
   thisSysTime.wMilliseconds = mMicrosecond / 1000;

                                                    // convert to FILETIME
   ntRes = SystemTimeToFileTime(&thisSysTime, &thisFileTime);
   assert(ntRes == TRUE);

   thisTime_i64 = (((int64_t)thisFileTime.dwHighDateTime) << 32) +
                  thisFileTime.dwLowDateTime;       // convert to int64_t

   // compute (thisFileTime - bootFileTime) and convert to an OsTime value
   deltaTime_i64  = thisTime_i64 - bootTime_i64;
   deltaSecs_i64  = (long) (deltaTime_i64 / FILETIME_UNITS_PER_SEC);
   deltaUsecs_i64 = (deltaTime_i64 % FILETIME_UNITS_PER_SEC) /
                     FILETIME_UNITS_PER_USEC;

   assert((deltaSecs_i64 >> 32)  == 0);
   assert((deltaUsecs_i64 >> 32) == 0);

   OsTime deltaOsTime((long) deltaSecs_i64, (long) deltaUsecs_i64);
   rTime = deltaOsTime;

   return OS_SUCCESS;
}