Bump version to 19.1.0-rc3
[llvm-project.git] / llvm / unittests / Support / UTCTimeTest.cpp
blob64e04d29376c3af1480d132e7422db124e99ffdb
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 //===----------------------------------------------------------------------===//
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"
15 namespace llvm {
16 namespace sys {
17 namespace {
19 TEST(UTCTime, convertutc) {
20 // Get the current time.
21 time_t currentTime;
22 time(&currentTime);
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));
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);
35 // Compare the formatted strings.
36 EXPECT_EQ(customResultString, StringRef(gmtimeResultString, 19));
39 } // namespace
40 } // namespace sys
41 } // namespace llvm