X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/bac41a7b9a0a9254fa30f8bb6e6038ab71a483e2..ce0ac947b4708d0bc1c7e6789b3e1f3bfc80d6e9:/cdsa/cdsa_utilities/timeflow.cpp?ds=sidebyside diff --git a/cdsa/cdsa_utilities/timeflow.cpp b/cdsa/cdsa_utilities/timeflow.cpp index 9814ce48..88566798 100644 --- a/cdsa/cdsa_utilities/timeflow.cpp +++ b/cdsa/cdsa_utilities/timeflow.cpp @@ -45,6 +45,9 @@ Absolute now() Absolute::Absolute(const struct timeval &tv) { mValue = tv.tv_sec + double(tv.tv_usec) / 1E6; } +Absolute::Absolute(const struct timespec &tv) +{ mValue = tv.tv_sec + double(tv.tv_nsec) / 1E9; } + Absolute::operator struct timeval () const { struct timeval tv; @@ -54,11 +57,25 @@ Absolute::operator struct timeval () const } else { tv.tv_sec = int32_t(mValue); double intPart; - tv.tv_usec = int32_t(modf(mValue, &intPart)); + tv.tv_usec = int32_t(modf(mValue, &intPart) * 1E6); } return tv; } +Absolute::operator struct timespec () const +{ + struct timespec ts; + if (mValue > LONG_MAX) { + ts.tv_sec = LONG_MAX; + ts.tv_nsec = 0; + } else { + ts.tv_sec = time_t(mValue); + double intPart; + ts.tv_nsec = int32_t(modf(mValue, &intPart) * 1E9); + } + return ts; +} + struct timeval Interval::timevalInterval() const { struct timeval tv; @@ -70,7 +87,7 @@ struct timeval Interval::timevalInterval() const } else { tv.tv_sec = int32_t(mValue); double intPart; - tv.tv_usec = int32_t(modf(mValue, &intPart)); + tv.tv_usec = int32_t(modf(mValue, &intPart) * 1E6); } return tv; }