summaryrefslogtreecommitdiff
path: root/absl/time/civil_time.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/time/civil_time.h')
-rw-r--r--absl/time/civil_time.h59
1 files changed, 55 insertions, 4 deletions
diff --git a/absl/time/civil_time.h b/absl/time/civil_time.h
index f0be303c..bb460044 100644
--- a/absl/time/civil_time.h
+++ b/absl/time/civil_time.h
@@ -76,7 +76,7 @@
#include "absl/time/internal/cctz/include/cctz/civil_time.h"
namespace absl {
-inline namespace lts_2019_08_08 {
+ABSL_NAMESPACE_BEGIN
namespace time_internal {
struct second_tag : cctz::detail::second_tag {};
@@ -248,7 +248,7 @@ struct year_tag : month_tag, cctz::detail::year_tag {};
// int minute()
// int second()
//
-// Recall that fields inferior to the type's aligment will be set to their
+// Recall that fields inferior to the type's alignment will be set to their
// minimum valid value.
//
// Example:
@@ -460,6 +460,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
@@ -469,7 +520,7 @@ namespace time_internal { // For functions found via ADL on civil-time tags.
//
// Example:
//
-// absl::CivilDay d = absl::CivilDay("1969-07-20");
+// absl::CivilDay d = absl::CivilDay(1969, 7, 20);
// std::cout << "Date is: " << d << "\n";
//
std::ostream& operator<<(std::ostream& os, CivilYear y);
@@ -481,7 +532,7 @@ std::ostream& operator<<(std::ostream& os, CivilSecond s);
} // namespace time_internal
-} // inline namespace lts_2019_08_08
+ABSL_NAMESPACE_END
} // namespace absl
#endif // ABSL_TIME_CIVIL_TIME_H_