aboutsummaryrefslogtreecommitdiff
path: root/libc/test/src/time/TmHelper.h
blob: 16210944bf15f9d3981d7cecfd065b2524af224c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//===---- TmHelper.h ------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_TEST_SRC_TIME_TMHELPER_H
#define LLVM_LIBC_TEST_SRC_TIME_TMHELPER_H

#include <time.h>

#include "src/time/time_utils.h"

using LIBC_NAMESPACE::time_utils::TimeConstants;

namespace LIBC_NAMESPACE {
namespace tmhelper {
namespace testing {

// A helper function to initialize tm data structure.
static inline void initialize_tm_data(struct tm *tm_data, int year, int month,
                                      int mday, int hour, int min, int sec,
                                      int wday, int yday) {
  struct tm temp = {.tm_sec = sec,
                    .tm_min = min,
                    .tm_hour = hour,
                    .tm_mday = mday,
                    .tm_mon = month - 1, // tm_mon starts with 0 for Jan
                    // years since 1900
                    .tm_year = year - TimeConstants::TIME_YEAR_BASE,
                    .tm_wday = wday,
                    .tm_yday = yday,
                    .tm_isdst = 0};
  *tm_data = temp;
}

} // namespace testing
} // namespace tmhelper
} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_TEST_SRC_TIME_TMHELPER_H