xref: /aosp_15_r20/external/llvm-libc/test/src/time/TmHelper.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===---- TmHelper.h ------------------------------------------*- 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_TEST_SRC_TIME_TMHELPER_H
10 #define LLVM_LIBC_TEST_SRC_TIME_TMHELPER_H
11 
12 #include <time.h>
13 
14 #include "src/__support/macros/config.h"
15 #include "src/time/time_utils.h"
16 
17 using LIBC_NAMESPACE::time_utils::TimeConstants;
18 
19 namespace LIBC_NAMESPACE_DECL {
20 namespace tmhelper {
21 namespace testing {
22 
23 // A helper function to initialize tm data structure.
initialize_tm_data(struct tm * tm_data,int year,int month,int mday,int hour,int min,int sec,int wday,int yday)24 static inline void initialize_tm_data(struct tm *tm_data, int year, int month,
25                                       int mday, int hour, int min, int sec,
26                                       int wday, int yday) {
27   struct tm temp = {.tm_sec = sec,
28                     .tm_min = min,
29                     .tm_hour = hour,
30                     .tm_mday = mday,
31                     .tm_mon = month - 1, // tm_mon starts with 0 for Jan
32                     // years since 1900
33                     .tm_year = year - TimeConstants::TIME_YEAR_BASE,
34                     .tm_wday = wday,
35                     .tm_yday = yday,
36                     .tm_isdst = 0};
37   *tm_data = temp;
38 }
39 
40 } // namespace testing
41 } // namespace tmhelper
42 } // namespace LIBC_NAMESPACE_DECL
43 
44 #endif // LLVM_LIBC_TEST_SRC_TIME_TMHELPER_H
45