about summary refs log tree commit diff
path: root/absl/time/civil_time.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-09-20T14·07-0700
committerShaindel Schwartz <shaindel@google.com>2019-09-20T14·40-0400
commitccdd1d57b6386ebc26fb0c7d99b604672437c124 (patch)
treebd2b466cbcf92fe15b5a6cd88a03ed8bdba33af7 /absl/time/civil_time.h
parentddf8e52a2918dd0ccec75d3e2426125fa3926724 (diff)
Export of internal Abseil changes
--
509c39cb5aa70893a180e5625e06cd9f76061ecf by Shaindel Schwartz <shaindel@google.com>:

Release CivilTime parsing API.

PiperOrigin-RevId: 270262448
GitOrigin-RevId: 509c39cb5aa70893a180e5625e06cd9f76061ecf
Change-Id: I343eb3062cdf6a2c53e6fddcaa35eb25d7478b1a
Diffstat (limited to 'absl/time/civil_time.h')
-rw-r--r--absl/time/civil_time.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/absl/time/civil_time.h b/absl/time/civil_time.h
index beaf7d898551..7c52586a1d7c 100644
--- a/absl/time/civil_time.h
+++ b/absl/time/civil_time.h
@@ -459,6 +459,57 @@ std::string FormatCivilTime(CivilDay c);
 std::string FormatCivilTime(CivilMonth c);
 std::string FormatCivilTime(CivilYear c);
 
+// absl::ParseCivilTime()
+//
+// Parses a civil-time value from the specified `absl::string_view` into the
+// passed output parameter. Returns `true` upon successful parsing.
+//
+// The expected form of the input string is as follows:
+//
+//  Type        | Format
+//  ---------------------------------
+//  CivilSecond | YYYY-MM-DDTHH:MM:SS
+//  CivilMinute | YYYY-MM-DDTHH:MM
+//  CivilHour   | YYYY-MM-DDTHH
+//  CivilDay    | YYYY-MM-DD
+//  CivilMonth  | YYYY-MM
+//  CivilYear   | YYYY
+//
+// Example:
+//
+//   absl::CivilDay d;
+//   bool ok = absl::ParseCivilTime("2018-01-02", &d); // OK
+//
+// Note that parsing will fail if the string's format does not match the
+// expected type exactly. `ParseLenientCivilTime()` below is more lenient.
+//
+bool ParseCivilTime(absl::string_view s, CivilSecond* c);
+bool ParseCivilTime(absl::string_view s, CivilMinute* c);
+bool ParseCivilTime(absl::string_view s, CivilHour* c);
+bool ParseCivilTime(absl::string_view s, CivilDay* c);
+bool ParseCivilTime(absl::string_view s, CivilMonth* c);
+bool ParseCivilTime(absl::string_view s, CivilYear* c);
+
+// ParseLenientCivilTime()
+//
+// Parses any of the formats accepted by `absl::ParseCivilTime()`, but is more
+// lenient if the format of the string does not exactly match the associated
+// type.
+//
+// Example:
+//
+//   absl::CivilDay d;
+//   bool ok = absl::ParseLenientCivilTime("1969-07-20", &d); // OK
+//   ok = absl::ParseLenientCivilTime("1969-07-20T10", &d);   // OK: T10 floored
+//   ok = absl::ParseLenientCivilTime("1969-07", &d);   // OK: day defaults to 1
+//
+bool ParseLenientCivilTime(absl::string_view s, CivilSecond* c);
+bool ParseLenientCivilTime(absl::string_view s, CivilMinute* c);
+bool ParseLenientCivilTime(absl::string_view s, CivilHour* c);
+bool ParseLenientCivilTime(absl::string_view s, CivilDay* c);
+bool ParseLenientCivilTime(absl::string_view s, CivilMonth* c);
+bool ParseLenientCivilTime(absl::string_view s, CivilYear* c);
+
 namespace time_internal {  // For functions found via ADL on civil-time tags.
 
 // Streaming Operators