Apollo  6.0
Open source self driving car software
time_util.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2017 The Apollo Authors. All Rights Reserved.
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 
17 #pragma once
18 
19 #include "cyber/common/macros.h"
20 
21 namespace apollo {
22 namespace common {
23 namespace util {
24 
25 class TimeUtil {
26  public:
27  // @brief: UNIX timestamp to GPS timestamp, in seconds.
28  static double Unix2Gps(double unix_time) {
29  double gps_time = unix_time - UNIX_GPS_DIFF;
30  if (unix_time < LEAP_SECOND_TIMESTAMP) {
31  gps_time -= 1.0;
32  }
33  return gps_time;
34  }
35 
36  // @brief: GPS timestamp to UNIX timestamp, in seconds.
37  static double Gps2Unix(double gps_time) {
38  double unix_time = gps_time + UNIX_GPS_DIFF;
39  if (unix_time + 1 < LEAP_SECOND_TIMESTAMP) {
40  unix_time += 1.0;
41  }
42  return unix_time;
43  }
44 
45  private:
46  // unix timestamp(1970.01.01) is different from gps timestamp(1980.01.06)
47  static const int UNIX_GPS_DIFF = 315964782;
48  // unix timestamp(2016.12.31 23:59:59(60) UTC/GMT)
49  static const int LEAP_SECOND_TIMESTAMP = 1483228799;
50 
51  DISALLOW_COPY_AND_ASSIGN(TimeUtil);
52 };
53 
54 } // namespace util
55 } // namespace common
56 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: time_util.h:25
static double Unix2Gps(double unix_time)
Definition: time_util.h:28
static double Gps2Unix(double gps_time)
Definition: time_util.h:37