diff --git a/src/libCom/osi/epicsTime.cpp b/src/libCom/osi/epicsTime.cpp index 097568c81..9c35b5c0a 100644 --- a/src/libCom/osi/epicsTime.cpp +++ b/src/libCom/osi/epicsTime.cpp @@ -10,6 +10,13 @@ /* epicsTime.cpp */ /* Author Jeffrey O. Hill */ +// Notes: +// 1) The epicsTime::nSec field is not public and so it could be +// changed to work more like the fractional seconds field in the NTP time +// stamp. That would significantly improve the precision of epicsTime on +// 64 bit architectures. +// + #include #include @@ -424,6 +431,31 @@ epicsTime::epicsTime ( const l_fp & ts ) ( ( ts.l_uf / NTP_FRACTION_DENOMINATOR ) * nSecPerSec ); } +epicsTime::operator epicsTimeStamp () const +{ + epicsTimeStamp ts; + // + // trucation by design + // ------------------- + // epicsTime::secPastEpoch is based on ulong and has much greater range + // on 64 bit hosts than the orginal epicsTimeStamp::secPastEpoch. The + // epicsTimeStamp::secPastEpoch is based on epicsUInt32 so that it will + // match the original network protocol. Of course one can anticipate + // that eventually, a epicsUInt64 based network time stamp will be + // introduced when 64 bit archectures are more ubiquitous. + // + // Truncation usually works fine here because the routines in this code + // that compute time stamp differences and compare time stamps produce + // good results when the operands are on either side of a time stamp + // rollover as long as the difference between the operands does not exceed + // 1/2 of full range. + // + ts.secPastEpoch = static_cast < epicsUInt32 > ( this->secPastEpoch ); + assert ( this->nSec < nSecPerSec ); + ts.nsec = static_cast < epicsUInt32 > ( this->nSec ); + return ts; +} + // return pointer to trailing "%0f" ( is a number) in a format string, // NULL if none; also return and a pointer to the "f" static char *fracFormat (const char *pFormat, unsigned long *width) diff --git a/src/libCom/osi/epicsTime.h b/src/libCom/osi/epicsTime.h index 254c9ae18..1a988564a 100644 --- a/src/libCom/osi/epicsTime.h +++ b/src/libCom/osi/epicsTime.h @@ -322,14 +322,6 @@ inline epicsTime & epicsTime::operator = ( const epicsTimeStamp & rhs ) return *this; } -inline epicsTime::operator epicsTimeStamp () const -{ - epicsTimeStamp ts; - ts.secPastEpoch = this->secPastEpoch; - ts.nsec = this->nSec; - return ts; -} - inline epicsTime & epicsTime::operator = ( const l_fp & rhs ) { *this = epicsTime ( rhs );