xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/common/platform/api/quiche_time_utils.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef QUICHE_COMMON_PLATFORM_API_QUICHE_TIME_UTILS_H_
6 #define QUICHE_COMMON_PLATFORM_API_QUICHE_TIME_UTILS_H_
7 
8 #include <cstdint>
9 
10 #include "quiche_platform_impl/quiche_time_utils_impl.h"
11 
12 namespace quiche {
13 
14 // Converts a civil time specified in UTC into a number of seconds since the
15 // Unix epoch.  This function is strict about validity of accepted dates.  For
16 // instance, it will reject February 29 on non-leap years, or 25 hours in a day.
17 // As a notable exception, 60 seconds is accepted to deal with potential leap
18 // seconds.  If the date predates Unix epoch, nullopt will be returned.
QuicheUtcDateTimeToUnixSeconds(int year,int month,int day,int hour,int minute,int second)19 inline std::optional<int64_t> QuicheUtcDateTimeToUnixSeconds(
20     int year, int month, int day, int hour, int minute, int second) {
21   return QuicheUtcDateTimeToUnixSecondsImpl(year, month, day, hour, minute,
22                                             second);
23 }
24 
25 }  // namespace quiche
26 
27 #endif  // QUICHE_COMMON_PLATFORM_API_QUICHE_TIME_UTILS_H_
28