Debian Codegraph @

llvm/unittests/Support/UTCTimeTest.cpp

raw
1 //===- unittests/Support/UTCTimeTest.cpp ----------------- ----------------===//
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 #include "llvm/Support/Chrono.h"
10 #include "gtest/gtest.h"
11 #include "llvm/Support/CommandLine.h"
12 #include "llvm/Support/FormatProviders.h"
13 #include "llvm/Support/FormatVariadic.h"
14
15 namespace llvm {
16 namespace sys {
17 namespace {
18
19 TEST(UTCTime, convertutc) {
20 // Get the current time.
21 time_t currentTime;
22 time(&currentTime);
23
24 // Convert with toUtcTime.
25 SmallString<15> customResultString;
26 raw_svector_ostream T(customResultString);
27 T << formatv("{0:%Y-%m-%d %H:%M:%S}", llvm::sys::toUtcTime(currentTime));
28
29 // Convert with gmtime.
30 char gmtimeResultString[20];
31 std::tm *gmtimeResult = std::gmtime(&currentTime);
32 assert(gmtimeResult != NULL);
33 std::strftime(gmtimeResultString, 20, "%Y-%m-%d %H:%M:%S", gmtimeResult);
34
35 // Compare the formatted strings.
36 EXPECT_EQ(customResultString, StringRef(gmtimeResultString, 19));
37
38 }
39 } // namespace
40 } // namespace sys
41 } // namespace llvm