added some time calc functions

This commit is contained in:
2014-08-01 17:17:00 +00:00
parent 019475149c
commit fdc0ce7623
2 changed files with 56 additions and 3 deletions

View File

@ -501,3 +501,33 @@ int qse_timelocal (const qse_btime_t* bt, qse_ntime_t* nt)
nt->nsec = 0;
return 0;
}
void qse_addtime (const qse_ntime_t* x, const qse_ntime_t* y, qse_ntime_t* z)
{
QSE_ASSERT (x->nsec < QSE_NSECS_PER_SEC);
QSE_ASSERT (y->nsec < QSE_NSECS_PER_SEC);
z->sec = x->sec + y->sec;
z->nsec = x->nsec + y->nsec;
if (z->nsec >= QSE_NSECS_PER_SEC)
{
z->sec = z->sec + 1;
z->nsec = z->nsec - QSE_NSECS_PER_SEC;
}
}
void qse_subtime (const qse_ntime_t* x, const qse_ntime_t* y, qse_ntime_t* z)
{
QSE_ASSERT (x->nsec < QSE_NSECS_PER_SEC);
QSE_ASSERT (y->nsec < QSE_NSECS_PER_SEC);
z->sec = x->sec - y->sec;
z->nsec = x->nsec - y->nsec;
if (z->nsec < 0)
{
z->sec = z->sec - 1;
z->nsec = z->nsec + QSE_NSECS_PER_SEC;
}
}