Path: blob/main/contrib/llvm-project/libcxx/include/__chrono/gps_clock.h
213766 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___CHRONO_GPS_CLOCK_H10#define _LIBCPP___CHRONO_GPS_CLOCK_H1112#include <version>13// Enable the contents of the header only when libc++ was built with experimental features enabled.14#if _LIBCPP_HAS_EXPERIMENTAL_TZDB1516# include <__assert>17# include <__chrono/duration.h>18# include <__chrono/time_point.h>19# include <__chrono/utc_clock.h>20# include <__config>21# include <__type_traits/common_type.h>2223# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)24# pragma GCC system_header25# endif2627_LIBCPP_PUSH_MACROS28# include <__undef_macros>2930_LIBCPP_BEGIN_NAMESPACE_STD3132# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION3334namespace chrono {3536class gps_clock;3738template <class _Duration>39using gps_time = time_point<gps_clock, _Duration>;40using gps_seconds = gps_time<seconds>;4142class gps_clock {43public:44using rep = utc_clock::rep;45using period = utc_clock::period;46using duration = chrono::duration<rep, period>;47using time_point = chrono::time_point<gps_clock>;48static constexpr bool is_steady = false; // The utc_clock is not steady.4950// The static difference between UTC and GPS time as specified in the Standard.51static constexpr chrono::seconds __offset{315964809};5253[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static time_point now() { return from_utc(utc_clock::now()); }5455template <class _Duration>56[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static utc_time<common_type_t<_Duration, seconds>>57to_utc(const gps_time<_Duration>& __time) noexcept {58using _Rp = common_type_t<_Duration, seconds>;59_Duration __time_since_epoch = __time.time_since_epoch();60_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__time_since_epoch >= utc_time<_Rp>::min().time_since_epoch() + __offset,61"the GPS to UTC conversion would underflow");6263return utc_time<_Rp>{__time_since_epoch + __offset};64}6566template <class _Duration>67[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static gps_time<common_type_t<_Duration, seconds>>68from_utc(const utc_time<_Duration>& __time) noexcept {69using _Rp = common_type_t<_Duration, seconds>;70_Duration __time_since_epoch = __time.time_since_epoch();71_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__time_since_epoch <= utc_time<_Rp>::max().time_since_epoch() - __offset,72"the UTC to GPS conversion would overflow");7374return gps_time<_Rp>{__time_since_epoch - __offset};75}76};7778} // namespace chrono7980# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&81// _LIBCPP_HAS_LOCALIZATION8283_LIBCPP_END_NAMESPACE_STD8485_LIBCPP_POP_MACROS8687#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB8889#endif // _LIBCPP___CHRONO_GPS_CLOCK_H909192