Apollo 10.0
自动驾驶开放平台
time_util.h
浏览该文件的文档.
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
21namespace apollo {
22namespace common {
23namespace util {
24
25class 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
52};
53
54} // namespace util
55} // namespace common
56} // namespace apollo
static double Gps2Unix(double gps_time)
Definition time_util.h:37
static double Unix2Gps(double unix_time)
Definition time_util.h:28
#define DISALLOW_COPY_AND_ASSIGN(classname)
Definition macros.h:48
class register implement
Definition arena_queue.h:37