aboutsummaryrefslogtreecommitdiffhomepage
path: root/absl/time/time.h
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-01-16 13:38:39 -0800
committerGravatar Xiaoyi Zhang <zhangxy@google.com>2020-01-21 11:47:40 -0500
commit159bf2bf6d1cc8087e02468d071e94d1177d1bae (patch)
tree5ba7def08ad7032867f629eaf431c496efbd24b3 /absl/time/time.h
parenta2e6adecc294dc4cd98cc285a9134ce58e0f2ad0 (diff)
Export of internal Abseil changes
-- c42a234e2c186bf697ce8d77e85628601fa514a6 by Abseil Team <absl-team@google.com>: Enable the assertion in the iterator's operator++ PiperOrigin-RevId: 290134813 -- f8c53ba8e9c5bb16bbcc1e412a5c2519c912c83e by Abseil Team <absl-team@google.com>: Define operator== and operator!= for absl::{weak,strong}_equality and absl::{partial,weak,strong}_ordering types themselves. PiperOrigin-RevId: 290111564 -- 36bc574090cefad74a451719ce2761982647a51d by Tom Manshreck <shreck@google.com>: Specify Time library flag formats PiperOrigin-RevId: 289928010 -- 26dd40281add260baab2b60fec05dfb9c5304aaa by Mark Barolak <mbar@google.com>: Delete an extraneous forward declaration of absl::Cord. PiperOrigin-RevId: 289708481 -- e60aea7f33554ff66d7699bb70e7af1d26323f1d by Abseil Team <absl-team@google.com>: Release b-tree benchmarks. PiperOrigin-RevId: 289654429 -- 660aa83fa000d4bae072b2d1c790f81d0939bc7e by Greg Falcon <gfalcon@google.com>: Use https links. Import of https://github.com/abseil/abseil-cpp/pull/586 PiperOrigin-RevId: 289479559 -- 0611ea4482dcf23d6b0a0389fe041eeb9052449a by Derek Mauro <dmauro@google.com>: Removes the static initializer for LookupTables<absl::uint128>::kVmaxOverBase Uses template specialization to hard code the resulting array. Static initializers are problematic for a number of reasons. Not only are they responsible for the static initialization order fiasco, but they are in the critical path during program startup. For these reasons, the Google C++ style guide strongly discourages them (and forbids them when they are not trivially destructible), and Chromium even has a test forbidding them. https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables https://chromium.googlesource.com/chromium/src.git/+/master/docs/static_initializers.md http://neugierig.org/software/chromium/notes/2011/08/static-initializers.html PiperOrigin-RevId: 289458677 -- c869362f6bb7a872314f74750d38d81bdaa73f95 by Greg Falcon <gfalcon@google.com>: Step 2 of 2 to fix our CCTZ fork to respect inline namespaces. Re-import of CCTZ from GitHub, applying new changes to honor Abseil's optional inline namespace in MSVC. PiperOrigin-RevId: 289454407 -- fdb3474d76c2ee0371ccdf7593a78137c03a3f58 by Greg Falcon <gfalcon@google.com>: Step 1 of 2 to fix our CCTZ fork to respect inline namespaces. CCTZ uses a linker flag to simulate weak symbol support in MSVC. This takes the form of a #pragma that includes the mangled names of two types: the symbol to treat as weak, and the symbol to use as its default value if no override is provided. When Abseil is configured to use inline namespaces, the mangled names of these symbols change, and the pragma should change to reflect that. Fortunately for us, MSVC name mangling is simple enough that we can generate the needed string literals in the preprocessor. This CL introduces the new macros; the uses will be introduced in a follow-up CL. PiperOrigin-RevId: 289435599 -- 5f152cc36f008acb9ab78f30b5efa40ebaf2754b by Matt Kulukundis <kfm@google.com>: Improve documentation for lazy_emplace PiperOrigin-RevId: 289333112 GitOrigin-RevId: c42a234e2c186bf697ce8d77e85628601fa514a6 Change-Id: I139ce6c7044a70d083af53e428bcb987f0fd88c6
Diffstat (limited to 'absl/time/time.h')
-rw-r--r--absl/time/time.h76
1 files changed, 58 insertions, 18 deletions
diff --git a/absl/time/time.h b/absl/time/time.h
index 7507b0c..1be5727 100644
--- a/absl/time/time.h
+++ b/absl/time/time.h
@@ -527,30 +527,59 @@ std::chrono::seconds ToChronoSeconds(Duration d);
std::chrono::minutes ToChronoMinutes(Duration d);
std::chrono::hours ToChronoHours(Duration d);
+
// FormatDuration()
//
-// Returns a string representing the duration in the form "72h3m0.5s".
-// Returns "inf" or "-inf" for +/- `InfiniteDuration()`.
+// Returns a string represention of the duration in a format consisting of a
+// possibly-signed prefix and a sequence of decimal numbers, each with an
+// optional fractional part and a unit suffix.
+//
+// Valid unit suffixes are "ns", "us" "ms", "s", "m", and "h".
+//
+// Simple examples include "300ms", "-1.5h", and "2h45m". Returns "inf" or
+// "-inf" for +/- `InfiniteDuration()` values and "0" for `ZeroDuration()`
+// values.
+//
+// This string format is used both as an input for parsing (when handling
+// command-line flags of type `absl::Duration`) and as an output in
+// `FormatDuration()`
std::string FormatDuration(Duration d);
-// Output stream operator.
-inline std::ostream& operator<<(std::ostream& os, Duration d) {
- return os << FormatDuration(d);
-}
-
// ParseDuration()
//
-// Parses a duration string consisting of a possibly signed sequence of
-// decimal numbers, each with an optional fractional part and a unit
-// suffix. The valid suffixes are "ns", "us" "ms", "s", "m", and "h".
-// Simple examples include "300ms", "-1.5h", and "2h45m". Parses "0" as
-// `ZeroDuration()`. Parses "inf" and "-inf" as +/- `InfiniteDuration()`.
+// Parses a `dur_string` of the format noted above into an `absl::Duration`
+// value.
+//
+// Parses "0" as a zero-length duration value. Parses "-inf" or "+inf" as
+// infinite durations values.
bool ParseDuration(const std::string& dur_string, Duration* d);
-// Support for flag values of type Duration. Duration flags must be specified
-// in a format that is valid input for absl::ParseDuration().
+// AbslParseFlag()
+//
+// Parses the command-line flag string representation `text` (using the format
+// noted above) into an `absl::Duration` destination, setting `error` on
+// failure.
+//
+// Example:
+//
+// --timeout=6h30m
+// --timeout=inf // Equivalent to `InfiniteDuration()`
+// --timeout=0 // Equivalent to `ZeroDuration()`
bool AbslParseFlag(absl::string_view text, Duration* dst, std::string* error);
+
+// AbslUnparseFlag()
+//
+// Unparses an `absl::Duration` into a command-line string representation using
+// the format noted above.
std::string AbslUnparseFlag(Duration d);
+
+// operator<<()
+//
+// Output stream operator, returning a stream in the format noted above.
+inline std::ostream& operator<<(std::ostream& os, Duration d) {
+ return os << FormatDuration(d);
+}
+
ABSL_DEPRECATED("Use AbslParseFlag() instead.")
bool ParseFlag(const std::string& text, Duration* dst, std::string* error);
ABSL_DEPRECATED("Use AbslUnparseFlag() instead.")
@@ -813,18 +842,29 @@ Time FromChrono(const std::chrono::system_clock::time_point& tp);
// // tp == std::chrono::system_clock::from_time_t(123);
std::chrono::system_clock::time_point ToChronoTime(Time);
-// Support for flag values of type Time. Time flags must be specified in a
-// format that matches absl::RFC3339_full. For example:
+// AbslParseFlag()
+//
+// Parses the command-line flag string representation `text` into an
+// `absl::Time` destination, setting `error` on failure. Time flag string
+// representations must be specified in a format that matches
+// `absl::RFC3339_full`.
+//
+// Example:
//
// --start_time=2016-01-02T03:04:05.678+08:00
//
// Note: A UTC offset (or 'Z' indicating a zero-offset from UTC) is required.
//
// Additionally, if you'd like to specify a time as a count of
-// seconds/milliseconds/etc from the Unix epoch, use an absl::Duration flag
-// and add that duration to absl::UnixEpoch() to get an absl::Time.
+// seconds/milliseconds/etc from the Unix epoch, use an `absl::Duration` flag
+// and add that duration to `absl::UnixEpoch()` to get an `absl::Time`.
bool AbslParseFlag(absl::string_view text, Time* t, std::string* error);
+
+// AbslUnparseFlag()
+//
+// Unparses an `absl::Time` into a command-line string format as noted above.
std::string AbslUnparseFlag(Time t);
+
ABSL_DEPRECATED("Use AbslParseFlag() instead.")
bool ParseFlag(const std::string& text, Time* t, std::string* error);
ABSL_DEPRECATED("Use AbslUnparseFlag() instead.")