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

source code of libc/test/src/time/TmHelper.h