1 // Copyright (C) 2019 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "icing/util/clock.h" 16 17 #include <chrono> // NOLINT. Abseil library is not available in AOSP so we have 18 // to use chrono to get current time in milliseconds. 19 #include <memory> 20 21 namespace icing { 22 namespace lib { 23 GetSteadyTimeNanoseconds()24int64_t GetSteadyTimeNanoseconds() { 25 return std::chrono::duration_cast<std::chrono::nanoseconds>( 26 std::chrono::steady_clock::now().time_since_epoch()) 27 .count(); 28 } 29 GetSteadyTimeMilliseconds()30int64_t GetSteadyTimeMilliseconds() { 31 return std::chrono::duration_cast<std::chrono::milliseconds>( 32 std::chrono::steady_clock::now().time_since_epoch()) 33 .count(); 34 } 35 GetSystemTimeMilliseconds() const36int64_t Clock::GetSystemTimeMilliseconds() const { 37 return std::chrono::duration_cast<std::chrono::milliseconds>( 38 std::chrono::system_clock::now().time_since_epoch()) 39 .count(); 40 } 41 GetNewTimer() const42std::unique_ptr<Timer> Clock::GetNewTimer() const { 43 return std::make_unique<Timer>(); 44 } 45 46 } // namespace lib 47 } // namespace icing 48