diff options
-rw-r--r-- | common/utils.cc | 6 | ||||
-rw-r--r-- | common/utils.h | 5 | ||||
-rw-r--r-- | common/utils_unittest.cc | 18 | ||||
-rw-r--r-- | update_attempter.cc | 2 |
4 files changed, 1 insertions, 30 deletions
diff --git a/common/utils.cc b/common/utils.cc index 844777ac..c6090135 100644 --- a/common/utils.cc +++ b/common/utils.cc @@ -914,12 +914,6 @@ ErrorCode GetBaseErrorCode(ErrorCode code) { return base_code; } -Time TimeFromStructTimespec(struct timespec *ts) { - int64_t us = static_cast<int64_t>(ts->tv_sec) * Time::kMicrosecondsPerSecond + - static_cast<int64_t>(ts->tv_nsec) / Time::kNanosecondsPerMicrosecond; - return Time::UnixEpoch() + TimeDelta::FromMicroseconds(us); -} - string StringVectorToString(const vector<string> &vec_str) { string str = "["; for (vector<string>::const_iterator i = vec_str.begin(); diff --git a/common/utils.h b/common/utils.h index 9da69904..4b83cc41 100644 --- a/common/utils.h +++ b/common/utils.h @@ -44,11 +44,6 @@ namespace chromeos_update_engine { namespace utils { -// Converts a struct timespec representing a number of seconds since -// the Unix epoch to a base::Time. Sub-microsecond time is rounded -// down. -base::Time TimeFromStructTimespec(struct timespec *ts); - // Formats |vec_str| as a string of the form ["<elem1>", "<elem2>"]. // Does no escaping, only use this for presentation in error messages. std::string StringVectorToString(const std::vector<std::string> &vec_str); diff --git a/common/utils_unittest.cc b/common/utils_unittest.cc index db885447..b30b2d2a 100644 --- a/common/utils_unittest.cc +++ b/common/utils_unittest.cc @@ -287,24 +287,6 @@ TEST(UtilsTest, FormatTimeDeltaTest) { "-1s"); } -TEST(UtilsTest, TimeFromStructTimespecTest) { - struct timespec ts; - - // Unix epoch (Thursday 00:00:00 UTC on Jan 1, 1970) - ts = (struct timespec) {.tv_sec = 0, .tv_nsec = 0}; - EXPECT_EQ(base::Time::UnixEpoch(), utils::TimeFromStructTimespec(&ts)); - - // 42 ms after the Unix billennium (Sunday 01:46:40 UTC on September 9, 2001) - ts = (struct timespec) {.tv_sec = 1000 * 1000 * 1000, - .tv_nsec = 42 * 1000 * 1000}; - base::Time::Exploded exploded = (base::Time::Exploded) { - .year = 2001, .month = 9, .day_of_week = 0, .day_of_month = 9, - .hour = 1, .minute = 46, .second = 40, .millisecond = 42}; - base::Time time; - EXPECT_TRUE(base::Time::FromUTCExploded(exploded, &time)); - EXPECT_EQ(time, utils::TimeFromStructTimespec(&ts)); -} - TEST(UtilsTest, ConvertToOmahaInstallDate) { // The Omaha Epoch starts at Jan 1, 2007 0:00 PST which is a // Monday. In Unix time, this point in time is easily obtained via diff --git a/update_attempter.cc b/update_attempter.cc index 5efd2573..5f323126 100644 --- a/update_attempter.cc +++ b/update_attempter.cc @@ -225,7 +225,7 @@ void UpdateAttempter::ReportOSAge() { return; } - Time lsb_release_timestamp = utils::TimeFromStructTimespec(&sb.st_ctim); + Time lsb_release_timestamp = Time::FromTimeSpec(sb.st_ctim); Time now = system_state_->clock()->GetWallclockTime(); TimeDelta age = now - lsb_release_timestamp; if (age.InSeconds() < 0) { |