diff options
author | Abseil Team <absl-team@google.com> | 2023-11-14 09:13:06 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-11-14 09:13:48 -0800 |
commit | 4a0255b16e85233849ec34c48f428ad8d2936eda (patch) | |
tree | 9a3e52cd268589fa6a64cd9437fde2d2204bd5d5 /absl/time/civil_time_test.cc | |
parent | 716fa00789b60ff52473eabc3ac201eb61744392 (diff) |
Support AbslStringify in absl Civil Time types.
PiperOrigin-RevId: 582342910
Change-Id: Iada5420867779ed352d8fb0695ff6d6044acfba2
Diffstat (limited to 'absl/time/civil_time_test.cc')
-rw-r--r-- | absl/time/civil_time_test.cc | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/absl/time/civil_time_test.cc b/absl/time/civil_time_test.cc index c7a085bf..19292a9c 100644 --- a/absl/time/civil_time_test.cc +++ b/absl/time/civil_time_test.cc @@ -19,8 +19,9 @@ #include <sstream> #include <type_traits> -#include "absl/base/macros.h" #include "gtest/gtest.h" +#include "absl/base/macros.h" +#include "absl/strings/str_format.h" namespace { @@ -869,6 +870,23 @@ TEST(CivilTime, ParseEdgeCases) { EXPECT_FALSE(absl::ParseLenientCivilTime("9223372036854775808", &y)) << y; } +TEST(CivilTime, AbslStringify) { + EXPECT_EQ("2015-01-02T03:04:05", + absl::StrFormat("%v", absl::CivilSecond(2015, 1, 2, 3, 4, 5))); + + EXPECT_EQ("2015-01-02T03:04", + absl::StrFormat("%v", absl::CivilMinute(2015, 1, 2, 3, 4))); + + EXPECT_EQ("2015-01-02T03", + absl::StrFormat("%v", absl::CivilHour(2015, 1, 2, 3))); + + EXPECT_EQ("2015-01-02", absl::StrFormat("%v", absl::CivilDay(2015, 1, 2))); + + EXPECT_EQ("2015-01", absl::StrFormat("%v", absl::CivilMonth(2015, 1))); + + EXPECT_EQ("2015", absl::StrFormat("%v", absl::CivilYear(2015))); +} + TEST(CivilTime, OutputStream) { absl::CivilSecond cs(2016, 2, 3, 4, 5, 6); { |