brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 64e04d2 Raw
42 lines · cpp
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-exception6//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 15namespace llvm {16namespace sys {17namespace {18 19TEST(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} // namespace40} // namespace sys41} // namespace llvm42