Commit 09eac4d5 by Abseil Team Committed by Copybara-Service

Import of CCTZ from GitHub.

PiperOrigin-RevId: 450445030
Change-Id: I1c1e5ed67f81a181454f7fc6751bf42a3bc2bc48
parent 9e408e05
...@@ -18,11 +18,15 @@ ...@@ -18,11 +18,15 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "absl/base/config.h"
#include "absl/time/internal/cctz/include/cctz/time_zone.h"
#if defined(__linux__)
#include <features.h>
#endif
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/base/config.h"
#include "absl/time/internal/cctz/include/cctz/civil_time.h" #include "absl/time/internal/cctz/include/cctz/civil_time.h"
#include "absl/time/internal/cctz/include/cctz/time_zone.h"
namespace chrono = std::chrono; namespace chrono = std::chrono;
...@@ -183,8 +187,10 @@ TEST(Format, PosixConversions) { ...@@ -183,8 +187,10 @@ TEST(Format, PosixConversions) {
TestFormatSpecifier(tp, tz, "%F", "1970-01-01"); TestFormatSpecifier(tp, tz, "%F", "1970-01-01");
TestFormatSpecifier(tp, tz, "%g", "70"); TestFormatSpecifier(tp, tz, "%g", "70");
TestFormatSpecifier(tp, tz, "%G", "1970"); TestFormatSpecifier(tp, tz, "%G", "1970");
#if defined(__GLIBC__)
TestFormatSpecifier(tp, tz, "%k", " 0"); TestFormatSpecifier(tp, tz, "%k", " 0");
TestFormatSpecifier(tp, tz, "%l", "12"); TestFormatSpecifier(tp, tz, "%l", "12");
#endif
TestFormatSpecifier(tp, tz, "%n", "\n"); TestFormatSpecifier(tp, tz, "%n", "\n");
TestFormatSpecifier(tp, tz, "%R", "00:00"); TestFormatSpecifier(tp, tz, "%R", "00:00");
TestFormatSpecifier(tp, tz, "%t", "\t"); TestFormatSpecifier(tp, tz, "%t", "\t");
...@@ -216,7 +222,9 @@ TEST(Format, LocaleSpecific) { ...@@ -216,7 +222,9 @@ TEST(Format, LocaleSpecific) {
#if defined(__linux__) #if defined(__linux__)
// SU/C99/TZ extensions // SU/C99/TZ extensions
TestFormatSpecifier(tp, tz, "%h", "Jan"); // Same as %b TestFormatSpecifier(tp, tz, "%h", "Jan"); // Same as %b
#if defined(__GLIBC__)
TestFormatSpecifier(tp, tz, "%P", "am"); TestFormatSpecifier(tp, tz, "%P", "am");
#endif
TestFormatSpecifier(tp, tz, "%r", "12:00:00 AM"); TestFormatSpecifier(tp, tz, "%r", "12:00:00 AM");
// Modified conversion specifiers %E_ // Modified conversion specifiers %E_
...@@ -1045,9 +1053,11 @@ TEST(Parse, LocaleSpecific) { ...@@ -1045,9 +1053,11 @@ TEST(Parse, LocaleSpecific) {
EXPECT_TRUE(parse("%h", "Feb", tz, &tp)); EXPECT_TRUE(parse("%h", "Feb", tz, &tp));
EXPECT_EQ(2, convert(tp, tz).month()); // Equivalent to %b EXPECT_EQ(2, convert(tp, tz).month()); // Equivalent to %b
#if defined(__GLIBC__)
tp = reset; tp = reset;
EXPECT_TRUE(parse("%l %p", "5 PM", tz, &tp)); EXPECT_TRUE(parse("%l %p", "5 PM", tz, &tp));
EXPECT_EQ(17, convert(tp, tz).hour()); EXPECT_EQ(17, convert(tp, tz).hour());
#endif
tp = reset; tp = reset;
EXPECT_TRUE(parse("%r", "03:44:55 PM", tz, &tp)); EXPECT_TRUE(parse("%r", "03:44:55 PM", tz, &tp));
...@@ -1055,6 +1065,7 @@ TEST(Parse, LocaleSpecific) { ...@@ -1055,6 +1065,7 @@ TEST(Parse, LocaleSpecific) {
EXPECT_EQ(44, convert(tp, tz).minute()); EXPECT_EQ(44, convert(tp, tz).minute());
EXPECT_EQ(55, convert(tp, tz).second()); EXPECT_EQ(55, convert(tp, tz).second());
#if defined(__GLIBC__)
tp = reset; tp = reset;
EXPECT_TRUE(parse("%Ec", "Tue Nov 19 05:06:07 2013", tz, &tp)); EXPECT_TRUE(parse("%Ec", "Tue Nov 19 05:06:07 2013", tz, &tp));
EXPECT_EQ(convert(civil_second(2013, 11, 19, 5, 6, 7), tz), tp); EXPECT_EQ(convert(civil_second(2013, 11, 19, 5, 6, 7), tz), tp);
...@@ -1126,6 +1137,7 @@ TEST(Parse, LocaleSpecific) { ...@@ -1126,6 +1137,7 @@ TEST(Parse, LocaleSpecific) {
EXPECT_TRUE(parse("%Oy", "04", tz, &tp)); EXPECT_TRUE(parse("%Oy", "04", tz, &tp));
EXPECT_EQ(2004, convert(tp, tz).year()); EXPECT_EQ(2004, convert(tp, tz).year());
#endif #endif
#endif
} }
TEST(Parse, ExtendedSeconds) { TEST(Parse, ExtendedSeconds) {
......
...@@ -21,10 +21,14 @@ ...@@ -21,10 +21,14 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include "gtest/gtest.h"
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/time/internal/cctz/include/cctz/civil_time.h"
#include "absl/time/internal/cctz/include/cctz/time_zone.h" #include "absl/time/internal/cctz/include/cctz/time_zone.h"
#if defined(__linux__)
#include <features.h>
#endif
#include "gtest/gtest.h"
#include "absl/time/internal/cctz/include/cctz/civil_time.h"
namespace chrono = std::chrono; namespace chrono = std::chrono;
...@@ -1043,7 +1047,7 @@ TEST(MakeTime, LocalTimeLibC) { ...@@ -1043,7 +1047,7 @@ TEST(MakeTime, LocalTimeLibC) {
// 1) we know how to change the time zone used by localtime()/mktime(), // 1) we know how to change the time zone used by localtime()/mktime(),
// 2) cctz and localtime()/mktime() will use similar-enough tzdata, and // 2) cctz and localtime()/mktime() will use similar-enough tzdata, and
// 3) we have some idea about how mktime() behaves during transitions. // 3) we have some idea about how mktime() behaves during transitions.
#if defined(__linux__) && !defined(__ANDROID__) #if defined(__linux__) && defined(__GLIBC__) && !defined(__ANDROID__)
const char* const ep = getenv("TZ"); const char* const ep = getenv("TZ");
std::string tz_name = (ep != nullptr) ? ep : ""; std::string tz_name = (ep != nullptr) ? ep : "";
for (const char* const* np = kTimeZoneNames; *np != nullptr; ++np) { for (const char* const* np = kTimeZoneNames; *np != nullptr; ++np) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment