cwTime.h/cpp : Added specToSeconds()

This commit is contained in:
kevin 2023-04-30 21:16:14 -04:00
parent f5993f4aad
commit 2d646837a6
2 changed files with 16 additions and 0 deletions

View File

@ -274,6 +274,20 @@ void cw::time::secondsToSpec( spec_t& ts, unsigned sec )
ts.tv_nsec = 0;
}
double cw::time::specToSeconds( const spec_t& t )
{
spec_t ts = t;
double sec = ts.tv_sec;
while( ts.tv_nsec >= 1e9 )
{
sec += 1.0;
ts.tv_nsec -= 1e9;
}
return sec + ((double)ts.tv_nsec)/1e9;
}
void cw::time::millisecondsToSpec( spec_t& ts, unsigned ms )
{
unsigned sec = ms/1000;

View File

@ -73,6 +73,8 @@ namespace cw
rc_t futureMs( spec_t& ts, unsigned ms );
void secondsToSpec( spec_t& ts, unsigned sec );
double specToSeconds( const spec_t& ts );
void millisecondsToSpec( spec_t& ts, unsigned ms );
void microsecondsToSpec( spec_t& ts, unsigned us );