time.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include <string>
20 
21 namespace cartographer {
22 namespace common {
23 
24 Duration FromSeconds(const double seconds) {
25  return std::chrono::duration_cast<Duration>(
26  std::chrono::duration<double>(seconds));
27 }
28 
29 double ToSeconds(const Duration duration) {
30  return std::chrono::duration_cast<std::chrono::duration<double>>(duration)
31  .count();
32 }
33 
34 Time FromUniversal(const int64 ticks) { return Time(Duration(ticks)); }
35 
36 int64 ToUniversal(const Time time) { return time.time_since_epoch().count(); }
37 
38 std::ostream& operator<<(std::ostream& os, const Time time) {
39  os << std::to_string(ToUniversal(time));
40  return os;
41 }
42 
44  return std::chrono::duration_cast<Duration>(
45  std::chrono::milliseconds(milliseconds));
46 }
47 
48 } // namespace common
49 } // namespace cartographer
common::Duration FromMilliseconds(const int64 milliseconds)
Definition: time.cc:43
std::ostream & operator<<(std::ostream &os, const Time time)
Definition: time.cc:38
int64_t int64
Definition: port.h:33
UniversalTimeScaleClock::time_point Time
Definition: time.h:44
Time FromUniversal(const int64 ticks)
Definition: time.cc:34
static time_point time
Duration FromSeconds(const double seconds)
Definition: time.cc:24
UniversalTimeScaleClock::duration Duration
Definition: time.h:43
int count
Definition: submap_3d.cc:33
int64 ToUniversal(const Time time)
Definition: time.cc:36
double ToSeconds(const Duration duration)
Definition: time.cc:29


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58