1 //===- unittests/Support/UTCTimeTest.cpp ----------------- ----------------===//
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
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"
19 TEST(UTCTime
, convertutc
) {
20 // Get the current time.
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(¤tTime
);
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));