xref: /aosp_15_r20/external/llvm-libc/src/__support/time/units.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===--- Time units conversion ----------------------------------*- C++ -*-===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIBC_SRC___SUPPORT_TIME_UNITS_H
10 #define LLVM_LIBC_SRC___SUPPORT_TIME_UNITS_H
11 
12 #include "hdr/types/time_t.h"
13 #include "src/__support/common.h"
14 #include "src/__support/macros/config.h"
15 
16 namespace LIBC_NAMESPACE_DECL {
17 namespace time_units {
18 LIBC_INLINE constexpr time_t operator""_s_ns(unsigned long long s) {
19   return static_cast<time_t>(s * 1'000'000'000);
20 }
21 LIBC_INLINE constexpr time_t operator""_s_us(unsigned long long s) {
22   return static_cast<time_t>(s * 1'000'000);
23 }
24 LIBC_INLINE constexpr time_t operator""_s_ms(unsigned long long s) {
25   return static_cast<time_t>(s * 1'000);
26 }
27 LIBC_INLINE constexpr time_t operator""_ms_ns(unsigned long long ms) {
28   return static_cast<time_t>(ms * 1'000'000);
29 }
30 LIBC_INLINE constexpr time_t operator""_ms_us(unsigned long long ms) {
31   return static_cast<time_t>(ms * 1'000);
32 }
33 LIBC_INLINE constexpr time_t operator""_us_ns(unsigned long long us) {
34   return static_cast<time_t>(us * 1'000);
35 }
36 } // namespace time_units
37 } // namespace LIBC_NAMESPACE_DECL
38 
39 #endif // LLVM_LIBC_SRC___SUPPORT_TIME_UNITS_H
40