blob: 96979f906dc7568707b2ef67b51c40d06fc12af4 [file] [log] [blame]
David Zeuthenf413fe52013-04-22 14:04:39 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "update_engine/clock.h"
6
7#include <time.h>
8
9namespace chromeos_update_engine {
10
11base::Time Clock::GetWallclockTime() {
12 return base::Time::Now();
13}
14
15base::Time Clock::GetMonotonicTime() {
16 struct timespec now_ts;
17 if (clock_gettime(CLOCK_MONOTONIC_RAW, &now_ts) != 0) {
18 // Avoid logging this as an error as call-sites may call this very
19 // often and we don't want to fill up the disk...
20 return base::Time();
21 }
22 struct timeval now_tv;
23 now_tv.tv_sec = now_ts.tv_sec;
24 now_tv.tv_usec = now_ts.tv_nsec/base::Time::kNanosecondsPerMicrosecond;
25 return base::Time::FromTimeVal(now_tv);
26}
27
28} // namespace chromeos_update_engine