time.h
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // -----------------------------------------------------------------------------
16 // File: time.h
17 // -----------------------------------------------------------------------------
18 //
19 // This header file defines abstractions for computing with absolute points
20 // in time, durations of time, and formatting and parsing time within a given
21 // time zone. The following abstractions are defined:
22 //
23 // * `absl::Time` defines an absolute, specific instance in time
24 // * `absl::Duration` defines a signed, fixed-length span of time
25 // * `absl::TimeZone` defines geopolitical time zone regions (as collected
26 // within the IANA Time Zone database (https://www.iana.org/time-zones)).
27 //
28 // Note: Absolute times are distinct from civil times, which refer to the
29 // human-scale time commonly represented by `YYYY-MM-DD hh:mm:ss`. The mapping
30 // between absolute and civil times can be specified by use of time zones
31 // (`absl::TimeZone` within this API). That is:
32 //
33 // Civil Time = F(Absolute Time, Time Zone)
34 // Absolute Time = G(Civil Time, Time Zone)
35 //
36 // See civil_time.h for abstractions related to constructing and manipulating
37 // civil time.
38 //
39 // Example:
40 //
41 // absl::TimeZone nyc;
42 // // LoadTimeZone() may fail so it's always better to check for success.
43 // if (!absl::LoadTimeZone("America/New_York", &nyc)) {
44 // // handle error case
45 // }
46 //
47 // // My flight leaves NYC on Jan 2, 2017 at 03:04:05
48 // absl::CivilSecond cs(2017, 1, 2, 3, 4, 5);
49 // absl::Time takeoff = absl::FromCivil(cs, nyc);
50 //
51 // absl::Duration flight_duration = absl::Hours(21) + absl::Minutes(35);
52 // absl::Time landing = takeoff + flight_duration;
53 //
54 // absl::TimeZone syd;
55 // if (!absl::LoadTimeZone("Australia/Sydney", &syd)) {
56 // // handle error case
57 // }
58 // std::string s = absl::FormatTime(
59 // "My flight will land in Sydney on %Y-%m-%d at %H:%M:%S",
60 // landing, syd);
61 
62 #ifndef ABSL_TIME_TIME_H_
63 #define ABSL_TIME_TIME_H_
64 
65 #if !defined(_MSC_VER)
66 #include <sys/time.h>
67 #else
68 #include <winsock2.h>
69 #endif
70 #include <chrono> // NOLINT(build/c++11)
71 #include <cmath>
72 #include <cstdint>
73 #include <ctime>
74 #include <ostream>
75 #include <string>
76 #include <type_traits>
77 #include <utility>
78 
80 #include "absl/time/civil_time.h"
82 
83 namespace absl {
84 
85 class Duration; // Defined below
86 class Time; // Defined below
87 class TimeZone; // Defined below
88 
89 namespace time_internal {
90 int64_t IDivDuration(bool satq, Duration num, Duration den, Duration* rem);
91 constexpr Time FromUnixDuration(Duration d);
92 constexpr Duration ToUnixDuration(Time t);
93 constexpr int64_t GetRepHi(Duration d);
94 constexpr uint32_t GetRepLo(Duration d);
95 constexpr Duration MakeDuration(int64_t hi, uint32_t lo);
96 constexpr Duration MakeDuration(int64_t hi, int64_t lo);
97 inline Duration MakePosDoubleDuration(double n);
98 constexpr int64_t kTicksPerNanosecond = 4;
99 constexpr int64_t kTicksPerSecond = 1000 * 1000 * 1000 * kTicksPerNanosecond;
100 template <std::intmax_t N>
101 constexpr Duration FromInt64(int64_t v, std::ratio<1, N>);
102 constexpr Duration FromInt64(int64_t v, std::ratio<60>);
103 constexpr Duration FromInt64(int64_t v, std::ratio<3600>);
104 template <typename T>
105 using EnableIfIntegral = typename std::enable_if<
107 template <typename T>
108 using EnableIfFloat =
110 } // namespace time_internal
111 
112 // Duration
113 //
114 // The `absl::Duration` class represents a signed, fixed-length span of time.
115 // A `Duration` is generated using a unit-specific factory function, or is
116 // the result of subtracting one `absl::Time` from another. Durations behave
117 // like unit-safe integers and they support all the natural integer-like
118 // arithmetic operations. Arithmetic overflows and saturates at +/- infinity.
119 // `Duration` should be passed by value rather than const reference.
120 //
121 // Factory functions `Nanoseconds()`, `Microseconds()`, `Milliseconds()`,
122 // `Seconds()`, `Minutes()`, `Hours()` and `InfiniteDuration()` allow for
123 // creation of constexpr `Duration` values
124 //
125 // Examples:
126 //
127 // constexpr absl::Duration ten_ns = absl::Nanoseconds(10);
128 // constexpr absl::Duration min = absl::Minutes(1);
129 // constexpr absl::Duration hour = absl::Hours(1);
130 // absl::Duration dur = 60 * min; // dur == hour
131 // absl::Duration half_sec = absl::Milliseconds(500);
132 // absl::Duration quarter_sec = 0.25 * absl::Seconds(1);
133 //
134 // `Duration` values can be easily converted to an integral number of units
135 // using the division operator.
136 //
137 // Example:
138 //
139 // constexpr absl::Duration dur = absl::Milliseconds(1500);
140 // int64_t ns = dur / absl::Nanoseconds(1); // ns == 1500000000
141 // int64_t ms = dur / absl::Milliseconds(1); // ms == 1500
142 // int64_t sec = dur / absl::Seconds(1); // sec == 1 (subseconds truncated)
143 // int64_t min = dur / absl::Minutes(1); // min == 0
144 //
145 // See the `IDivDuration()` and `FDivDuration()` functions below for details on
146 // how to access the fractional parts of the quotient.
147 //
148 // Alternatively, conversions can be performed using helpers such as
149 // `ToInt64Microseconds()` and `ToDoubleSeconds()`.
150 class Duration {
151  public:
152  // Value semantics.
153  constexpr Duration() : rep_hi_(0), rep_lo_(0) {} // zero-length duration
154 
155  // Copyable.
156 #if !defined(__clang__) && defined(_MSC_VER) && _MSC_VER < 1910
157  // Explicitly defining the constexpr copy constructor avoids an MSVC bug.
158  constexpr Duration(const Duration& d)
159  : rep_hi_(d.rep_hi_), rep_lo_(d.rep_lo_) {}
160 #else
161  constexpr Duration(const Duration& d) = default;
162 #endif
163  Duration& operator=(const Duration& d) = default;
164 
165  // Compound assignment operators.
166  Duration& operator+=(Duration d);
167  Duration& operator-=(Duration d);
168  Duration& operator*=(int64_t r);
169  Duration& operator*=(double r);
170  Duration& operator/=(int64_t r);
171  Duration& operator/=(double r);
172  Duration& operator%=(Duration rhs);
173 
174  // Overloads that forward to either the int64_t or double overloads above.
175  template <typename T>
176  Duration& operator*=(T r) {
177  int64_t x = r;
178  return *this *= x;
179  }
180  template <typename T>
181  Duration& operator/=(T r) {
182  int64_t x = r;
183  return *this /= x;
184  }
185  Duration& operator*=(float r) { return *this *= static_cast<double>(r); }
186  Duration& operator/=(float r) { return *this /= static_cast<double>(r); }
187 
188  template <typename H>
189  friend H AbslHashValue(H h, Duration d) {
190  return H::combine(std::move(h), d.rep_hi_, d.rep_lo_);
191  }
192 
193  private:
194  friend constexpr int64_t time_internal::GetRepHi(Duration d);
195  friend constexpr uint32_t time_internal::GetRepLo(Duration d);
196  friend constexpr Duration time_internal::MakeDuration(int64_t hi,
197  uint32_t lo);
198  constexpr Duration(int64_t hi, uint32_t lo) : rep_hi_(hi), rep_lo_(lo) {}
199  int64_t rep_hi_;
200  uint32_t rep_lo_;
201 };
202 
203 // Relational Operators
204 constexpr bool operator<(Duration lhs, Duration rhs);
205 constexpr bool operator>(Duration lhs, Duration rhs) { return rhs < lhs; }
206 constexpr bool operator>=(Duration lhs, Duration rhs) { return !(lhs < rhs); }
207 constexpr bool operator<=(Duration lhs, Duration rhs) { return !(rhs < lhs); }
208 constexpr bool operator==(Duration lhs, Duration rhs);
209 constexpr bool operator!=(Duration lhs, Duration rhs) { return !(lhs == rhs); }
210 
211 // Additive Operators
212 constexpr Duration operator-(Duration d);
213 inline Duration operator+(Duration lhs, Duration rhs) { return lhs += rhs; }
214 inline Duration operator-(Duration lhs, Duration rhs) { return lhs -= rhs; }
215 
216 // Multiplicative Operators
217 template <typename T>
219  return lhs *= rhs;
220 }
221 template <typename T>
223  return rhs *= lhs;
224 }
225 template <typename T>
227  return lhs /= rhs;
228 }
229 inline int64_t operator/(Duration lhs, Duration rhs) {
230  return time_internal::IDivDuration(true, lhs, rhs,
231  &lhs); // trunc towards zero
232 }
233 inline Duration operator%(Duration lhs, Duration rhs) { return lhs %= rhs; }
234 
235 // IDivDuration()
236 //
237 // Divides a numerator `Duration` by a denominator `Duration`, returning the
238 // quotient and remainder. The remainder always has the same sign as the
239 // numerator. The returned quotient and remainder respect the identity:
240 //
241 // numerator = denominator * quotient + remainder
242 //
243 // Returned quotients are capped to the range of `int64_t`, with the difference
244 // spilling into the remainder to uphold the above identity. This means that the
245 // remainder returned could differ from the remainder returned by
246 // `Duration::operator%` for huge quotients.
247 //
248 // See also the notes on `InfiniteDuration()` below regarding the behavior of
249 // division involving zero and infinite durations.
250 //
251 // Example:
252 //
253 // constexpr absl::Duration a =
254 // absl::Seconds(std::numeric_limits<int64_t>::max()); // big
255 // constexpr absl::Duration b = absl::Nanoseconds(1); // small
256 //
257 // absl::Duration rem = a % b;
258 // // rem == absl::ZeroDuration()
259 //
260 // // Here, q would overflow int64_t, so rem accounts for the difference.
261 // int64_t q = absl::IDivDuration(a, b, &rem);
262 // // q == std::numeric_limits<int64_t>::max(), rem == a - b * q
263 inline int64_t IDivDuration(Duration num, Duration den, Duration* rem) {
264  return time_internal::IDivDuration(true, num, den,
265  rem); // trunc towards zero
266 }
267 
268 // FDivDuration()
269 //
270 // Divides a `Duration` numerator into a fractional number of units of a
271 // `Duration` denominator.
272 //
273 // See also the notes on `InfiniteDuration()` below regarding the behavior of
274 // division involving zero and infinite durations.
275 //
276 // Example:
277 //
278 // double d = absl::FDivDuration(absl::Milliseconds(1500), absl::Seconds(1));
279 // // d == 1.5
280 double FDivDuration(Duration num, Duration den);
281 
282 // ZeroDuration()
283 //
284 // Returns a zero-length duration. This function behaves just like the default
285 // constructor, but the name helps make the semantics clear at call sites.
286 constexpr Duration ZeroDuration() { return Duration(); }
287 
288 // AbsDuration()
289 //
290 // Returns the absolute value of a duration.
292  return (d < ZeroDuration()) ? -d : d;
293 }
294 
295 // Trunc()
296 //
297 // Truncates a duration (toward zero) to a multiple of a non-zero unit.
298 //
299 // Example:
300 //
301 // absl::Duration d = absl::Nanoseconds(123456789);
302 // absl::Duration a = absl::Trunc(d, absl::Microseconds(1)); // 123456us
304 
305 // Floor()
306 //
307 // Floors a duration using the passed duration unit to its largest value not
308 // greater than the duration.
309 //
310 // Example:
311 //
312 // absl::Duration d = absl::Nanoseconds(123456789);
313 // absl::Duration b = absl::Floor(d, absl::Microseconds(1)); // 123456us
315 
316 // Ceil()
317 //
318 // Returns the ceiling of a duration using the passed duration unit to its
319 // smallest value not less than the duration.
320 //
321 // Example:
322 //
323 // absl::Duration d = absl::Nanoseconds(123456789);
324 // absl::Duration c = absl::Ceil(d, absl::Microseconds(1)); // 123457us
325 Duration Ceil(Duration d, Duration unit);
326 
327 // InfiniteDuration()
328 //
329 // Returns an infinite `Duration`. To get a `Duration` representing negative
330 // infinity, use `-InfiniteDuration()`.
331 //
332 // Duration arithmetic overflows to +/- infinity and saturates. In general,
333 // arithmetic with `Duration` infinities is similar to IEEE 754 infinities
334 // except where IEEE 754 NaN would be involved, in which case +/-
335 // `InfiniteDuration()` is used in place of a "nan" Duration.
336 //
337 // Examples:
338 //
339 // constexpr absl::Duration inf = absl::InfiniteDuration();
340 // const absl::Duration d = ... any finite duration ...
341 //
342 // inf == inf + inf
343 // inf == inf + d
344 // inf == inf - inf
345 // -inf == d - inf
346 //
347 // inf == d * 1e100
348 // inf == inf / 2
349 // 0 == d / inf
350 // INT64_MAX == inf / d
351 //
352 // d < inf
353 // -inf < d
354 //
355 // // Division by zero returns infinity, or INT64_MIN/MAX where appropriate.
356 // inf == d / 0
357 // INT64_MAX == d / absl::ZeroDuration()
358 //
359 // The examples involving the `/` operator above also apply to `IDivDuration()`
360 // and `FDivDuration()`.
361 constexpr Duration InfiniteDuration();
362 
363 // Nanoseconds()
364 // Microseconds()
365 // Milliseconds()
366 // Seconds()
367 // Minutes()
368 // Hours()
369 //
370 // Factory functions for constructing `Duration` values from an integral number
371 // of the unit indicated by the factory function's name.
372 //
373 // Note: no "Days()" factory function exists because "a day" is ambiguous.
374 // Civil days are not always 24 hours long, and a 24-hour duration often does
375 // not correspond with a civil day. If a 24-hour duration is needed, use
376 // `absl::Hours(24)`. (If you actually want a civil day, use absl::CivilDay
377 // from civil_time.h.)
378 //
379 // Example:
380 //
381 // absl::Duration a = absl::Seconds(60);
382 // absl::Duration b = absl::Minutes(1); // b == a
383 constexpr Duration Nanoseconds(int64_t n);
384 constexpr Duration Microseconds(int64_t n);
385 constexpr Duration Milliseconds(int64_t n);
386 constexpr Duration Seconds(int64_t n);
387 constexpr Duration Minutes(int64_t n);
388 constexpr Duration Hours(int64_t n);
389 
390 // Factory overloads for constructing `Duration` values from a floating-point
391 // number of the unit indicated by the factory function's name. These functions
392 // exist for convenience, but they are not as efficient as the integral
393 // factories, which should be preferred.
394 //
395 // Example:
396 //
397 // auto a = absl::Seconds(1.5); // OK
398 // auto b = absl::Milliseconds(1500); // BETTER
399 template <typename T, time_internal::EnableIfFloat<T> = 0>
401  return n * Nanoseconds(1);
402 }
403 template <typename T, time_internal::EnableIfFloat<T> = 0>
405  return n * Microseconds(1);
406 }
407 template <typename T, time_internal::EnableIfFloat<T> = 0>
409  return n * Milliseconds(1);
410 }
411 template <typename T, time_internal::EnableIfFloat<T> = 0>
413  if (n >= 0) { // Note: `NaN >= 0` is false.
414  if (n >= (std::numeric_limits<int64_t>::max)()) return InfiniteDuration();
416  } else {
417  if (std::isnan(n))
418  return std::signbit(n) ? -InfiniteDuration() : InfiniteDuration();
419  if (n <= (std::numeric_limits<int64_t>::min)()) return -InfiniteDuration();
421  }
422 }
423 template <typename T, time_internal::EnableIfFloat<T> = 0>
425  return n * Minutes(1);
426 }
427 template <typename T, time_internal::EnableIfFloat<T> = 0>
429  return n * Hours(1);
430 }
431 
432 // ToInt64Nanoseconds()
433 // ToInt64Microseconds()
434 // ToInt64Milliseconds()
435 // ToInt64Seconds()
436 // ToInt64Minutes()
437 // ToInt64Hours()
438 //
439 // Helper functions that convert a Duration to an integral count of the
440 // indicated unit. These functions are shorthand for the `IDivDuration()`
441 // function above; see its documentation for details about overflow, etc.
442 //
443 // Example:
444 //
445 // absl::Duration d = absl::Milliseconds(1500);
446 // int64_t isec = absl::ToInt64Seconds(d); // isec == 1
447 int64_t ToInt64Nanoseconds(Duration d);
448 int64_t ToInt64Microseconds(Duration d);
449 int64_t ToInt64Milliseconds(Duration d);
450 int64_t ToInt64Seconds(Duration d);
451 int64_t ToInt64Minutes(Duration d);
452 int64_t ToInt64Hours(Duration d);
453 
454 // ToDoubleNanoSeconds()
455 // ToDoubleMicroseconds()
456 // ToDoubleMilliseconds()
457 // ToDoubleSeconds()
458 // ToDoubleMinutes()
459 // ToDoubleHours()
460 //
461 // Helper functions that convert a Duration to a floating point count of the
462 // indicated unit. These functions are shorthand for the `FDivDuration()`
463 // function above; see its documentation for details about overflow, etc.
464 //
465 // Example:
466 //
467 // absl::Duration d = absl::Milliseconds(1500);
468 // double dsec = absl::ToDoubleSeconds(d); // dsec == 1.5
469 double ToDoubleNanoseconds(Duration d);
472 double ToDoubleSeconds(Duration d);
473 double ToDoubleMinutes(Duration d);
474 double ToDoubleHours(Duration d);
475 
476 // FromChrono()
477 //
478 // Converts any of the pre-defined std::chrono durations to an absl::Duration.
479 //
480 // Example:
481 //
482 // std::chrono::milliseconds ms(123);
483 // absl::Duration d = absl::FromChrono(ms);
484 constexpr Duration FromChrono(const std::chrono::nanoseconds& d);
485 constexpr Duration FromChrono(const std::chrono::microseconds& d);
486 constexpr Duration FromChrono(const std::chrono::milliseconds& d);
487 constexpr Duration FromChrono(const std::chrono::seconds& d);
488 constexpr Duration FromChrono(const std::chrono::minutes& d);
489 constexpr Duration FromChrono(const std::chrono::hours& d);
490 
491 // ToChronoNanoseconds()
492 // ToChronoMicroseconds()
493 // ToChronoMilliseconds()
494 // ToChronoSeconds()
495 // ToChronoMinutes()
496 // ToChronoHours()
497 //
498 // Converts an absl::Duration to any of the pre-defined std::chrono durations.
499 // If overflow would occur, the returned value will saturate at the min/max
500 // chrono duration value instead.
501 //
502 // Example:
503 //
504 // absl::Duration d = absl::Microseconds(123);
505 // auto x = absl::ToChronoMicroseconds(d);
506 // auto y = absl::ToChronoNanoseconds(d); // x == y
507 // auto z = absl::ToChronoSeconds(absl::InfiniteDuration());
508 // // z == std::chrono::seconds::max()
509 std::chrono::nanoseconds ToChronoNanoseconds(Duration d);
510 std::chrono::microseconds ToChronoMicroseconds(Duration d);
511 std::chrono::milliseconds ToChronoMilliseconds(Duration d);
513 std::chrono::minutes ToChronoMinutes(Duration d);
514 std::chrono::hours ToChronoHours(Duration d);
515 
516 // FormatDuration()
517 //
518 // Returns a string representing the duration in the form "72h3m0.5s".
519 // Returns "inf" or "-inf" for +/- `InfiniteDuration()`.
520 std::string FormatDuration(Duration d);
521 
522 // Output stream operator.
523 inline std::ostream& operator<<(std::ostream& os, Duration d) {
524  return os << FormatDuration(d);
525 }
526 
527 // ParseDuration()
528 //
529 // Parses a duration string consisting of a possibly signed sequence of
530 // decimal numbers, each with an optional fractional part and a unit
531 // suffix. The valid suffixes are "ns", "us" "ms", "s", "m", and "h".
532 // Simple examples include "300ms", "-1.5h", and "2h45m". Parses "0" as
533 // `ZeroDuration()`. Parses "inf" and "-inf" as +/- `InfiniteDuration()`.
534 bool ParseDuration(const std::string& dur_string, Duration* d);
535 
536 // Support for flag values of type Duration. Duration flags must be specified
537 // in a format that is valid input for absl::ParseDuration().
538 bool ParseFlag(const std::string& text, Duration* dst, std::string* error);
539 std::string UnparseFlag(Duration d);
540 
541 // Time
542 //
543 // An `absl::Time` represents a specific instant in time. Arithmetic operators
544 // are provided for naturally expressing time calculations. Instances are
545 // created using `absl::Now()` and the `absl::From*()` factory functions that
546 // accept the gamut of other time representations. Formatting and parsing
547 // functions are provided for conversion to and from strings. `absl::Time`
548 // should be passed by value rather than const reference.
549 //
550 // `absl::Time` assumes there are 60 seconds in a minute, which means the
551 // underlying time scales must be "smeared" to eliminate leap seconds.
552 // See https://developers.google.com/time/smear.
553 //
554 // Even though `absl::Time` supports a wide range of timestamps, exercise
555 // caution when using values in the distant past. `absl::Time` uses the
556 // Proleptic Gregorian calendar, which extends the Gregorian calendar backward
557 // to dates before its introduction in 1582.
558 // See https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar
559 // for more information. Use the ICU calendar classes to convert a date in
560 // some other calendar (http://userguide.icu-project.org/datetime/calendar).
561 //
562 // Similarly, standardized time zones are a reasonably recent innovation, with
563 // the Greenwich prime meridian being established in 1884. The TZ database
564 // itself does not profess accurate offsets for timestamps prior to 1970. The
565 // breakdown of future timestamps is subject to the whim of regional
566 // governments.
567 //
568 // The `absl::Time` class represents an instant in time as a count of clock
569 // ticks of some granularity (resolution) from some starting point (epoch).
570 //
571 // `absl::Time` uses a resolution that is high enough to avoid loss in
572 // precision, and a range that is wide enough to avoid overflow, when
573 // converting between tick counts in most Google time scales (i.e., resolution
574 // of at least one nanosecond, and range +/-100 billion years). Conversions
575 // between the time scales are performed by truncating (towards negative
576 // infinity) to the nearest representable point.
577 //
578 // Examples:
579 //
580 // absl::Time t1 = ...;
581 // absl::Time t2 = t1 + absl::Minutes(2);
582 // absl::Duration d = t2 - t1; // == absl::Minutes(2)
583 //
584 class Time {
585  public:
586  // Value semantics.
587 
588  // Returns the Unix epoch. However, those reading your code may not know
589  // or expect the Unix epoch as the default value, so make your code more
590  // readable by explicitly initializing all instances before use.
591  //
592  // Example:
593  // absl::Time t = absl::UnixEpoch();
594  // absl::Time t = absl::Now();
595  // absl::Time t = absl::TimeFromTimeval(tv);
596  // absl::Time t = absl::InfinitePast();
597  constexpr Time() = default;
598 
599  // Copyable.
600  constexpr Time(const Time& t) = default;
601  Time& operator=(const Time& t) = default;
602 
603  // Assignment operators.
605  rep_ += d;
606  return *this;
607  }
609  rep_ -= d;
610  return *this;
611  }
612 
613  // Time::Breakdown
614  //
615  // The calendar and wall-clock (aka "civil time") components of an
616  // `absl::Time` in a certain `absl::TimeZone`. This struct is not
617  // intended to represent an instant in time. So, rather than passing
618  // a `Time::Breakdown` to a function, pass an `absl::Time` and an
619  // `absl::TimeZone`.
620  //
621  // Deprecated. Use `absl::TimeZone::CivilInfo`.
622  struct
623  Breakdown {
624  int64_t year; // year (e.g., 2013)
625  int month; // month of year [1:12]
626  int day; // day of month [1:31]
627  int hour; // hour of day [0:23]
628  int minute; // minute of hour [0:59]
629  int second; // second of minute [0:59]
630  Duration subsecond; // [Seconds(0):Seconds(1)) if finite
631  int weekday; // 1==Mon, ..., 7=Sun
632  int yearday; // day of year [1:366]
633 
634  // Note: The following fields exist for backward compatibility
635  // with older APIs. Accessing these fields directly is a sign of
636  // imprudent logic in the calling code. Modern time-related code
637  // should only access this data indirectly by way of FormatTime().
638  // These fields are undefined for InfiniteFuture() and InfinitePast().
639  int offset; // seconds east of UTC
640  bool is_dst; // is offset non-standard?
641  const char* zone_abbr; // time-zone abbreviation (e.g., "PST")
642  };
643 
644  // Time::In()
645  //
646  // Returns the breakdown of this instant in the given TimeZone.
647  //
648  // Deprecated. Use `absl::TimeZone::At(Time)`.
649  Breakdown In(TimeZone tz) const;
650 
651  template <typename H>
652  friend H AbslHashValue(H h, Time t) {
653  return H::combine(std::move(h), t.rep_);
654  }
655 
656  private:
657  friend constexpr Time time_internal::FromUnixDuration(Duration d);
658  friend constexpr Duration time_internal::ToUnixDuration(Time t);
659  friend constexpr bool operator<(Time lhs, Time rhs);
660  friend constexpr bool operator==(Time lhs, Time rhs);
661  friend Duration operator-(Time lhs, Time rhs);
662  friend constexpr Time UniversalEpoch();
663  friend constexpr Time InfiniteFuture();
664  friend constexpr Time InfinitePast();
665  constexpr explicit Time(Duration rep) : rep_(rep) {}
667 };
668 
669 // Relational Operators
670 constexpr bool operator<(Time lhs, Time rhs) { return lhs.rep_ < rhs.rep_; }
671 constexpr bool operator>(Time lhs, Time rhs) { return rhs < lhs; }
672 constexpr bool operator>=(Time lhs, Time rhs) { return !(lhs < rhs); }
673 constexpr bool operator<=(Time lhs, Time rhs) { return !(rhs < lhs); }
674 constexpr bool operator==(Time lhs, Time rhs) { return lhs.rep_ == rhs.rep_; }
675 constexpr bool operator!=(Time lhs, Time rhs) { return !(lhs == rhs); }
676 
677 // Additive Operators
678 inline Time operator+(Time lhs, Duration rhs) { return lhs += rhs; }
679 inline Time operator+(Duration lhs, Time rhs) { return rhs += lhs; }
680 inline Time operator-(Time lhs, Duration rhs) { return lhs -= rhs; }
681 inline Duration operator-(Time lhs, Time rhs) { return lhs.rep_ - rhs.rep_; }
682 
683 // UnixEpoch()
684 //
685 // Returns the `absl::Time` representing "1970-01-01 00:00:00.0 +0000".
686 constexpr Time UnixEpoch() { return Time(); }
687 
688 // UniversalEpoch()
689 //
690 // Returns the `absl::Time` representing "0001-01-01 00:00:00.0 +0000", the
691 // epoch of the ICU Universal Time Scale.
692 constexpr Time UniversalEpoch() {
693  // 719162 is the number of days from 0001-01-01 to 1970-01-01,
694  // assuming the Gregorian calendar.
695  return Time(time_internal::MakeDuration(-24 * 719162 * int64_t{3600}, 0U));
696 }
697 
698 // InfiniteFuture()
699 //
700 // Returns an `absl::Time` that is infinitely far in the future.
701 constexpr Time InfiniteFuture() {
702  return Time(
703  time_internal::MakeDuration((std::numeric_limits<int64_t>::max)(), ~0U));
704 }
705 
706 // InfinitePast()
707 //
708 // Returns an `absl::Time` that is infinitely far in the past.
709 constexpr Time InfinitePast() {
710  return Time(
711  time_internal::MakeDuration((std::numeric_limits<int64_t>::min)(), ~0U));
712 }
713 
714 // FromUnixNanos()
715 // FromUnixMicros()
716 // FromUnixMillis()
717 // FromUnixSeconds()
718 // FromTimeT()
719 // FromUDate()
720 // FromUniversal()
721 //
722 // Creates an `absl::Time` from a variety of other representations.
723 constexpr Time FromUnixNanos(int64_t ns);
724 constexpr Time FromUnixMicros(int64_t us);
725 constexpr Time FromUnixMillis(int64_t ms);
726 constexpr Time FromUnixSeconds(int64_t s);
727 constexpr Time FromTimeT(time_t t);
728 Time FromUDate(double udate);
729 Time FromUniversal(int64_t universal);
730 
731 // ToUnixNanos()
732 // ToUnixMicros()
733 // ToUnixMillis()
734 // ToUnixSeconds()
735 // ToTimeT()
736 // ToUDate()
737 // ToUniversal()
738 //
739 // Converts an `absl::Time` to a variety of other representations. Note that
740 // these operations round down toward negative infinity where necessary to
741 // adjust to the resolution of the result type. Beware of possible time_t
742 // over/underflow in ToTime{T,val,spec}() on 32-bit platforms.
743 int64_t ToUnixNanos(Time t);
744 int64_t ToUnixMicros(Time t);
745 int64_t ToUnixMillis(Time t);
746 int64_t ToUnixSeconds(Time t);
747 time_t ToTimeT(Time t);
748 double ToUDate(Time t);
749 int64_t ToUniversal(Time t);
750 
751 // DurationFromTimespec()
752 // DurationFromTimeval()
753 // ToTimespec()
754 // ToTimeval()
755 // TimeFromTimespec()
756 // TimeFromTimeval()
757 // ToTimespec()
758 // ToTimeval()
759 //
760 // Some APIs use a timespec or a timeval as a Duration (e.g., nanosleep(2)
761 // and select(2)), while others use them as a Time (e.g. clock_gettime(2)
762 // and gettimeofday(2)), so conversion functions are provided for both cases.
763 // The "to timespec/val" direction is easily handled via overloading, but
764 // for "from timespec/val" the desired type is part of the function name.
765 Duration DurationFromTimespec(timespec ts);
766 Duration DurationFromTimeval(timeval tv);
767 timespec ToTimespec(Duration d);
768 timeval ToTimeval(Duration d);
769 Time TimeFromTimespec(timespec ts);
770 Time TimeFromTimeval(timeval tv);
771 timespec ToTimespec(Time t);
772 timeval ToTimeval(Time t);
773 
774 // FromChrono()
775 //
776 // Converts a std::chrono::system_clock::time_point to an absl::Time.
777 //
778 // Example:
779 //
780 // auto tp = std::chrono::system_clock::from_time_t(123);
781 // absl::Time t = absl::FromChrono(tp);
782 // // t == absl::FromTimeT(123)
784 
785 // ToChronoTime()
786 //
787 // Converts an absl::Time to a std::chrono::system_clock::time_point. If
788 // overflow would occur, the returned value will saturate at the min/max time
789 // point value instead.
790 //
791 // Example:
792 //
793 // absl::Time t = absl::FromTimeT(123);
794 // auto tp = absl::ToChronoTime(t);
795 // // tp == std::chrono::system_clock::from_time_t(123);
797 
798 // Support for flag values of type Time. Time flags must be specified in a
799 // format that matches absl::RFC3339_full. For example:
800 //
801 // --start_time=2016-01-02T03:04:05.678+08:00
802 //
803 // Note: A UTC offset (or 'Z' indicating a zero-offset from UTC) is required.
804 //
805 // Additionally, if you'd like to specify a time as a count of
806 // seconds/milliseconds/etc from the Unix epoch, use an absl::Duration flag
807 // and add that duration to absl::UnixEpoch() to get an absl::Time.
808 bool ParseFlag(const std::string& text, Time* t, std::string* error);
809 std::string UnparseFlag(Time t);
810 
811 // TimeZone
812 //
813 // The `absl::TimeZone` is an opaque, small, value-type class representing a
814 // geo-political region within which particular rules are used for converting
815 // between absolute and civil times (see https://git.io/v59Ly). `absl::TimeZone`
816 // values are named using the TZ identifiers from the IANA Time Zone Database,
817 // such as "America/Los_Angeles" or "Australia/Sydney". `absl::TimeZone` values
818 // are created from factory functions such as `absl::LoadTimeZone()`. Note:
819 // strings like "PST" and "EDT" are not valid TZ identifiers. Prefer to pass by
820 // value rather than const reference.
821 //
822 // For more on the fundamental concepts of time zones, absolute times, and civil
823 // times, see https://github.com/google/cctz#fundamental-concepts
824 //
825 // Examples:
826 //
827 // absl::TimeZone utc = absl::UTCTimeZone();
828 // absl::TimeZone pst = absl::FixedTimeZone(-8 * 60 * 60);
829 // absl::TimeZone loc = absl::LocalTimeZone();
830 // absl::TimeZone lax;
831 // if (!absl::LoadTimeZone("America/Los_Angeles", &lax)) {
832 // // handle error case
833 // }
834 //
835 // See also:
836 // - https://github.com/google/cctz
837 // - https://www.iana.org/time-zones
838 // - https://en.wikipedia.org/wiki/Zoneinfo
839 class TimeZone {
840  public:
841  explicit TimeZone(time_internal::cctz::time_zone tz) : cz_(tz) {}
842  TimeZone() = default; // UTC, but prefer UTCTimeZone() to be explicit.
843 
844  // Copyable.
845  TimeZone(const TimeZone&) = default;
846  TimeZone& operator=(const TimeZone&) = default;
847 
848  explicit operator time_internal::cctz::time_zone() const { return cz_; }
849 
850  std::string name() const { return cz_.name(); }
851 
852  // TimeZone::CivilInfo
853  //
854  // Information about the civil time corresponding to an absolute time.
855  // This struct is not intended to represent an instant in time. So, rather
856  // than passing a `TimeZone::CivilInfo` to a function, pass an `absl::Time`
857  // and an `absl::TimeZone`.
858  struct CivilInfo {
861 
862  // Note: The following fields exist for backward compatibility
863  // with older APIs. Accessing these fields directly is a sign of
864  // imprudent logic in the calling code. Modern time-related code
865  // should only access this data indirectly by way of FormatTime().
866  // These fields are undefined for InfiniteFuture() and InfinitePast().
867  int offset; // seconds east of UTC
868  bool is_dst; // is offset non-standard?
869  const char* zone_abbr; // time-zone abbreviation (e.g., "PST")
870  };
871 
872  // TimeZone::At(Time)
873  //
874  // Returns the civil time for this TimeZone at a certain `absl::Time`.
875  // If the input time is infinite, the output civil second will be set to
876  // CivilSecond::max() or min(), and the subsecond will be infinite.
877  //
878  // Example:
879  //
880  // const auto epoch = lax.At(absl::UnixEpoch());
881  // // epoch.cs == 1969-12-31 16:00:00
882  // // epoch.subsecond == absl::ZeroDuration()
883  // // epoch.offset == -28800
884  // // epoch.is_dst == false
885  // // epoch.abbr == "PST"
886  CivilInfo At(Time t) const;
887 
888  // TimeZone::TimeInfo
889  //
890  // Information about the absolute times corresponding to a civil time.
891  // (Subseconds must be handled separately.)
892  //
893  // It is possible for a caller to pass a civil-time value that does
894  // not represent an actual or unique instant in time (due to a shift
895  // in UTC offset in the TimeZone, which results in a discontinuity in
896  // the civil-time components). For example, a daylight-saving-time
897  // transition skips or repeats civil times---in the United States,
898  // March 13, 2011 02:15 never occurred, while November 6, 2011 01:15
899  // occurred twice---so requests for such times are not well-defined.
900  // To account for these possibilities, `absl::TimeZone::TimeInfo` is
901  // richer than just a single `absl::Time`.
902  struct TimeInfo {
903  enum CivilKind {
904  UNIQUE, // the civil time was singular (pre == trans == post)
905  SKIPPED, // the civil time did not exist (pre >= trans > post)
906  REPEATED, // the civil time was ambiguous (pre < trans <= post)
907  } kind;
908  Time pre; // time calculated using the pre-transition offset
909  Time trans; // when the civil-time discontinuity occurred
910  Time post; // time calculated using the post-transition offset
911  };
912 
913  // TimeZone::At(CivilSecond)
914  //
915  // Returns an `absl::TimeInfo` containing the absolute time(s) for this
916  // TimeZone at an `absl::CivilSecond`. When the civil time is skipped or
917  // repeated, returns times calculated using the pre-transition and post-
918  // transition UTC offsets, plus the transition time itself.
919  //
920  // Examples:
921  //
922  // // A unique civil time
923  // const auto jan01 = lax.At(absl::CivilSecond(2011, 1, 1, 0, 0, 0));
924  // // jan01.kind == TimeZone::TimeInfo::UNIQUE
925  // // jan01.pre is 2011-01-01 00:00:00 -0800
926  // // jan01.trans is 2011-01-01 00:00:00 -0800
927  // // jan01.post is 2011-01-01 00:00:00 -0800
928  //
929  // // A Spring DST transition, when there is a gap in civil time
930  // const auto mar13 = lax.At(absl::CivilSecond(2011, 3, 13, 2, 15, 0));
931  // // mar13.kind == TimeZone::TimeInfo::SKIPPED
932  // // mar13.pre is 2011-03-13 03:15:00 -0700
933  // // mar13.trans is 2011-03-13 03:00:00 -0700
934  // // mar13.post is 2011-03-13 01:15:00 -0800
935  //
936  // // A Fall DST transition, when civil times are repeated
937  // const auto nov06 = lax.At(absl::CivilSecond(2011, 11, 6, 1, 15, 0));
938  // // nov06.kind == TimeZone::TimeInfo::REPEATED
939  // // nov06.pre is 2011-11-06 01:15:00 -0700
940  // // nov06.trans is 2011-11-06 01:00:00 -0800
941  // // nov06.post is 2011-11-06 01:15:00 -0800
942  TimeInfo At(CivilSecond ct) const;
943 
944  // TimeZone::NextTransition()
945  // TimeZone::PrevTransition()
946  //
947  // Finds the time of the next/previous offset change in this time zone.
948  //
949  // By definition, `NextTransition(t, &trans)` returns false when `t` is
950  // `InfiniteFuture()`, and `PrevTransition(t, &trans)` returns false
951  // when `t` is `InfinitePast()`. If the zone has no transitions, the
952  // result will also be false no matter what the argument.
953  //
954  // Otherwise, when `t` is `InfinitePast()`, `NextTransition(t, &trans)`
955  // returns true and sets `trans` to the first recorded transition. Chains
956  // of calls to `NextTransition()/PrevTransition()` will eventually return
957  // false, but it is unspecified exactly when `NextTransition(t, &trans)`
958  // jumps to false, or what time is set by `PrevTransition(t, &trans)` for
959  // a very distant `t`.
960  //
961  // Note: Enumeration of time-zone transitions is for informational purposes
962  // only. Modern time-related code should not care about when offset changes
963  // occur.
964  //
965  // Example:
966  // absl::TimeZone nyc;
967  // if (!absl::LoadTimeZone("America/New_York", &nyc)) { ... }
968  // const auto now = absl::Now();
969  // auto t = absl::InfinitePast();
970  // absl::TimeZone::CivilTransition trans;
971  // while (t <= now && nyc.NextTransition(t, &trans)) {
972  // // transition: trans.from -> trans.to
973  // t = nyc.At(trans.to).trans;
974  // }
976  CivilSecond from; // the civil time we jump from
977  CivilSecond to; // the civil time we jump to
978  };
979  bool NextTransition(Time t, CivilTransition* trans) const;
980  bool PrevTransition(Time t, CivilTransition* trans) const;
981 
982  template <typename H>
983  friend H AbslHashValue(H h, TimeZone tz) {
984  return H::combine(std::move(h), tz.cz_);
985  }
986 
987  private:
988  friend bool operator==(TimeZone a, TimeZone b) { return a.cz_ == b.cz_; }
989  friend bool operator!=(TimeZone a, TimeZone b) { return a.cz_ != b.cz_; }
990  friend std::ostream& operator<<(std::ostream& os, TimeZone tz) {
991  return os << tz.name();
992  }
993 
995 };
996 
997 // LoadTimeZone()
998 //
999 // Loads the named zone. May perform I/O on the initial load of the named
1000 // zone. If the name is invalid, or some other kind of error occurs, returns
1001 // `false` and `*tz` is set to the UTC time zone.
1002 inline bool LoadTimeZone(const std::string& name, TimeZone* tz) {
1003  if (name == "localtime") {
1005  return true;
1006  }
1008  const bool b = time_internal::cctz::load_time_zone(name, &cz);
1009  *tz = TimeZone(cz);
1010  return b;
1011 }
1012 
1013 // FixedTimeZone()
1014 //
1015 // Returns a TimeZone that is a fixed offset (seconds east) from UTC.
1016 // Note: If the absolute value of the offset is greater than 24 hours
1017 // you'll get UTC (i.e., no offset) instead.
1019  return TimeZone(
1021 }
1022 
1023 // UTCTimeZone()
1024 //
1025 // Convenience method returning the UTC time zone.
1028 }
1029 
1030 // LocalTimeZone()
1031 //
1032 // Convenience method returning the local time zone, or UTC if there is
1033 // no configured local zone. Warning: Be wary of using LocalTimeZone(),
1034 // and particularly so in a server process, as the zone configured for the
1035 // local machine should be irrelevant. Prefer an explicit zone name.
1038 }
1039 
1040 // ToCivilSecond()
1041 // ToCivilMinute()
1042 // ToCivilHour()
1043 // ToCivilDay()
1044 // ToCivilMonth()
1045 // ToCivilYear()
1046 //
1047 // Helpers for TimeZone::At(Time) to return particularly aligned civil times.
1048 //
1049 // Example:
1050 //
1051 // absl::Time t = ...;
1052 // absl::TimeZone tz = ...;
1053 // const auto cd = absl::ToCivilDay(t, tz);
1055  return tz.At(t).cs; // already a CivilSecond
1056 }
1058  return CivilMinute(tz.At(t).cs);
1059 }
1061  return CivilHour(tz.At(t).cs);
1062 }
1064  return CivilDay(tz.At(t).cs);
1065 }
1067  return CivilMonth(tz.At(t).cs);
1068 }
1070  return CivilYear(tz.At(t).cs);
1071 }
1072 
1073 // FromCivil()
1074 //
1075 // Helper for TimeZone::At(CivilSecond) that provides "order-preserving
1076 // semantics." If the civil time maps to a unique time, that time is
1077 // returned. If the civil time is repeated in the given time zone, the
1078 // time using the pre-transition offset is returned. Otherwise, the
1079 // civil time is skipped in the given time zone, and the transition time
1080 // is returned. This means that for any two civil times, ct1 and ct2,
1081 // (ct1 < ct2) => (FromCivil(ct1) <= FromCivil(ct2)), the equal case
1082 // being when two non-existent civil times map to the same transition time.
1083 //
1084 // Note: Accepts civil times of any alignment.
1086  const auto ti = tz.At(ct);
1087  if (ti.kind == TimeZone::TimeInfo::SKIPPED) return ti.trans;
1088  return ti.pre;
1089 }
1090 
1091 // TimeConversion
1092 //
1093 // An `absl::TimeConversion` represents the conversion of year, month, day,
1094 // hour, minute, and second values (i.e., a civil time), in a particular
1095 // `absl::TimeZone`, to a time instant (an absolute time), as returned by
1096 // `absl::ConvertDateTime()`. Lecacy version of `absl::TimeZone::TimeInfo`.
1097 //
1098 // Deprecated. Use `absl::TimeZone::TimeInfo`.
1099 struct
1100  TimeConversion {
1101  Time pre; // time calculated using the pre-transition offset
1102  Time trans; // when the civil-time discontinuity occurred
1103  Time post; // time calculated using the post-transition offset
1104 
1105  enum Kind {
1106  UNIQUE, // the civil time was singular (pre == trans == post)
1107  SKIPPED, // the civil time did not exist
1108  REPEATED, // the civil time was ambiguous
1109  };
1111 
1112  bool normalized; // input values were outside their valid ranges
1113 };
1114 
1115 // ConvertDateTime()
1116 //
1117 // Legacy version of `absl::TimeZone::At(absl::CivilSecond)` that takes
1118 // the civil time as six, separate values (YMDHMS).
1119 //
1120 // The input month, day, hour, minute, and second values can be outside
1121 // of their valid ranges, in which case they will be "normalized" during
1122 // the conversion.
1123 //
1124 // Example:
1125 //
1126 // // "October 32" normalizes to "November 1".
1127 // absl::TimeConversion tc =
1128 // absl::ConvertDateTime(2013, 10, 32, 8, 30, 0, lax);
1129 // // tc.kind == TimeConversion::UNIQUE && tc.normalized == true
1130 // // absl::ToCivilDay(tc.pre, tz).month() == 11
1131 // // absl::ToCivilDay(tc.pre, tz).day() == 1
1132 //
1133 // Deprecated. Use `absl::TimeZone::At(CivilSecond)`.
1134 TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour,
1135  int min, int sec, TimeZone tz);
1136 
1137 // FromDateTime()
1138 //
1139 // A convenience wrapper for `absl::ConvertDateTime()` that simply returns
1140 // the "pre" `absl::Time`. That is, the unique result, or the instant that
1141 // is correct using the pre-transition offset (as if the transition never
1142 // happened).
1143 //
1144 // Example:
1145 //
1146 // absl::Time t = absl::FromDateTime(2017, 9, 26, 9, 30, 0, lax);
1147 // // t = 2017-09-26 09:30:00 -0700
1148 //
1149 // Deprecated. Use `absl::FromCivil(CivilSecond, TimeZone)`. Note that the
1150 // behavior of `FromCivil()` differs from `FromDateTime()` for skipped civil
1151 // times. If you care about that see `absl::TimeZone::At(absl::CivilSecond)`.
1152 inline Time FromDateTime(int64_t year, int mon, int day, int hour,
1153  int min, int sec, TimeZone tz) {
1154  return ConvertDateTime(year, mon, day, hour, min, sec, tz).pre;
1155 }
1156 
1157 // FromTM()
1158 //
1159 // Converts the `tm_year`, `tm_mon`, `tm_mday`, `tm_hour`, `tm_min`, and
1160 // `tm_sec` fields to an `absl::Time` using the given time zone. See ctime(3)
1161 // for a description of the expected values of the tm fields. If the indicated
1162 // time instant is not unique (see `absl::TimeZone::At(absl::CivilSecond)`
1163 // above), the `tm_isdst` field is consulted to select the desired instant
1164 // (`tm_isdst` > 0 means DST, `tm_isdst` == 0 means no DST, `tm_isdst` < 0
1165 // means use the post-transition offset).
1166 Time FromTM(const struct tm& tm, TimeZone tz);
1167 
1168 // ToTM()
1169 //
1170 // Converts the given `absl::Time` to a struct tm using the given time zone.
1171 // See ctime(3) for a description of the values of the tm fields.
1172 struct tm ToTM(Time t, TimeZone tz);
1173 
1174 // RFC3339_full
1175 // RFC3339_sec
1176 //
1177 // FormatTime()/ParseTime() format specifiers for RFC3339 date/time strings,
1178 // with trailing zeros trimmed or with fractional seconds omitted altogether.
1179 //
1180 // Note that RFC3339_sec[] matches an ISO 8601 extended format for date and
1181 // time with UTC offset. Also note the use of "%Y": RFC3339 mandates that
1182 // years have exactly four digits, but we allow them to take their natural
1183 // width.
1184 extern const char RFC3339_full[]; // %Y-%m-%dT%H:%M:%E*S%Ez
1185 extern const char RFC3339_sec[]; // %Y-%m-%dT%H:%M:%S%Ez
1186 
1187 // RFC1123_full
1188 // RFC1123_no_wday
1189 //
1190 // FormatTime()/ParseTime() format specifiers for RFC1123 date/time strings.
1191 extern const char RFC1123_full[]; // %a, %d %b %E4Y %H:%M:%S %z
1192 extern const char RFC1123_no_wday[]; // %d %b %E4Y %H:%M:%S %z
1193 
1194 // FormatTime()
1195 //
1196 // Formats the given `absl::Time` in the `absl::TimeZone` according to the
1197 // provided format string. Uses strftime()-like formatting options, with
1198 // the following extensions:
1199 //
1200 // - %Ez - RFC3339-compatible numeric UTC offset (+hh:mm or -hh:mm)
1201 // - %E*z - Full-resolution numeric UTC offset (+hh:mm:ss or -hh:mm:ss)
1202 // - %E#S - Seconds with # digits of fractional precision
1203 // - %E*S - Seconds with full fractional precision (a literal '*')
1204 // - %E#f - Fractional seconds with # digits of precision
1205 // - %E*f - Fractional seconds with full precision (a literal '*')
1206 // - %E4Y - Four-character years (-999 ... -001, 0000, 0001 ... 9999)
1207 //
1208 // Note that %E0S behaves like %S, and %E0f produces no characters. In
1209 // contrast %E*f always produces at least one digit, which may be '0'.
1210 //
1211 // Note that %Y produces as many characters as it takes to fully render the
1212 // year. A year outside of [-999:9999] when formatted with %E4Y will produce
1213 // more than four characters, just like %Y.
1214 //
1215 // We recommend that format strings include the UTC offset (%z, %Ez, or %E*z)
1216 // so that the result uniquely identifies a time instant.
1217 //
1218 // Example:
1219 //
1220 // absl::CivilSecond cs(2013, 1, 2, 3, 4, 5);
1221 // absl::Time t = absl::FromCivil(cs, lax);
1222 // std::string f = absl::FormatTime("%H:%M:%S", t, lax); // "03:04:05"
1223 // f = absl::FormatTime("%H:%M:%E3S", t, lax); // "03:04:05.000"
1224 //
1225 // Note: If the given `absl::Time` is `absl::InfiniteFuture()`, the returned
1226 // string will be exactly "infinite-future". If the given `absl::Time` is
1227 // `absl::InfinitePast()`, the returned string will be exactly "infinite-past".
1228 // In both cases the given format string and `absl::TimeZone` are ignored.
1229 //
1230 std::string FormatTime(const std::string& format, Time t, TimeZone tz);
1231 
1232 // Convenience functions that format the given time using the RFC3339_full
1233 // format. The first overload uses the provided TimeZone, while the second
1234 // uses LocalTimeZone().
1235 std::string FormatTime(Time t, TimeZone tz);
1236 std::string FormatTime(Time t);
1237 
1238 // Output stream operator.
1239 inline std::ostream& operator<<(std::ostream& os, Time t) {
1240  return os << FormatTime(t);
1241 }
1242 
1243 // ParseTime()
1244 //
1245 // Parses an input string according to the provided format string and
1246 // returns the corresponding `absl::Time`. Uses strftime()-like formatting
1247 // options, with the same extensions as FormatTime(), but with the
1248 // exceptions that %E#S is interpreted as %E*S, and %E#f as %E*f. %Ez
1249 // and %E*z also accept the same inputs.
1250 //
1251 // %Y consumes as many numeric characters as it can, so the matching data
1252 // should always be terminated with a non-numeric. %E4Y always consumes
1253 // exactly four characters, including any sign.
1254 //
1255 // Unspecified fields are taken from the default date and time of ...
1256 //
1257 // "1970-01-01 00:00:00.0 +0000"
1258 //
1259 // For example, parsing a string of "15:45" (%H:%M) will return an absl::Time
1260 // that represents "1970-01-01 15:45:00.0 +0000".
1261 //
1262 // Note that since ParseTime() returns time instants, it makes the most sense
1263 // to parse fully-specified date/time strings that include a UTC offset (%z,
1264 // %Ez, or %E*z).
1265 //
1266 // Note also that `absl::ParseTime()` only heeds the fields year, month, day,
1267 // hour, minute, (fractional) second, and UTC offset. Other fields, like
1268 // weekday (%a or %A), while parsed for syntactic validity, are ignored
1269 // in the conversion.
1270 //
1271 // Date and time fields that are out-of-range will be treated as errors
1272 // rather than normalizing them like `absl::CivilSecond` does. For example,
1273 // it is an error to parse the date "Oct 32, 2013" because 32 is out of range.
1274 //
1275 // A leap second of ":60" is normalized to ":00" of the following minute
1276 // with fractional seconds discarded. The following table shows how the
1277 // given seconds and subseconds will be parsed:
1278 //
1279 // "59.x" -> 59.x // exact
1280 // "60.x" -> 00.0 // normalized
1281 // "00.x" -> 00.x // exact
1282 //
1283 // Errors are indicated by returning false and assigning an error message
1284 // to the "err" out param if it is non-null.
1285 //
1286 // Note: If the input string is exactly "infinite-future", the returned
1287 // `absl::Time` will be `absl::InfiniteFuture()` and `true` will be returned.
1288 // If the input string is "infinite-past", the returned `absl::Time` will be
1289 // `absl::InfinitePast()` and `true` will be returned.
1290 //
1291 bool ParseTime(const std::string& format, const std::string& input, Time* time,
1292  std::string* err);
1293 
1294 // Like ParseTime() above, but if the format string does not contain a UTC
1295 // offset specification (%z/%Ez/%E*z) then the input is interpreted in the
1296 // given TimeZone. This means that the input, by itself, does not identify a
1297 // unique instant. Being time-zone dependent, it also admits the possibility
1298 // of ambiguity or non-existence, in which case the "pre" time (as defined
1299 // by TimeZone::TimeInfo) is returned. For these reasons we recommend that
1300 // all date/time strings include a UTC offset so they're context independent.
1301 bool ParseTime(const std::string& format, const std::string& input, TimeZone tz,
1302  Time* time, std::string* err);
1303 
1304 // ============================================================================
1305 // Implementation Details Follow
1306 // ============================================================================
1307 
1308 namespace time_internal {
1309 
1310 // Creates a Duration with a given representation.
1311 // REQUIRES: hi,lo is a valid representation of a Duration as specified
1312 // in time/duration.cc.
1313 constexpr Duration MakeDuration(int64_t hi, uint32_t lo = 0) {
1314  return Duration(hi, lo);
1315 }
1316 
1317 constexpr Duration MakeDuration(int64_t hi, int64_t lo) {
1318  return MakeDuration(hi, static_cast<uint32_t>(lo));
1319 }
1320 
1321 // Make a Duration value from a floating-point number, as long as that number
1322 // is in the range [ 0 .. numeric_limits<int64_t>::max ), that is, as long as
1323 // it's positive and can be converted to int64_t without risk of UB.
1325  const int64_t int_secs = static_cast<int64_t>(n);
1326  const uint32_t ticks =
1327  static_cast<uint32_t>((n - int_secs) * kTicksPerSecond + 0.5);
1328  return ticks < kTicksPerSecond
1329  ? MakeDuration(int_secs, ticks)
1330  : MakeDuration(int_secs + 1, ticks - kTicksPerSecond);
1331 }
1332 
1333 // Creates a normalized Duration from an almost-normalized (sec,ticks)
1334 // pair. sec may be positive or negative. ticks must be in the range
1335 // -kTicksPerSecond < *ticks < kTicksPerSecond. If ticks is negative it
1336 // will be normalized to a positive value in the resulting Duration.
1337 constexpr Duration MakeNormalizedDuration(int64_t sec, int64_t ticks) {
1338  return (ticks < 0) ? MakeDuration(sec - 1, ticks + kTicksPerSecond)
1339  : MakeDuration(sec, ticks);
1340 }
1341 
1342 // Provide access to the Duration representation.
1343 constexpr int64_t GetRepHi(Duration d) { return d.rep_hi_; }
1344 constexpr uint32_t GetRepLo(Duration d) { return d.rep_lo_; }
1345 
1346 // Returns true iff d is positive or negative infinity.
1347 constexpr bool IsInfiniteDuration(Duration d) { return GetRepLo(d) == ~0U; }
1348 
1349 // Returns an infinite Duration with the opposite sign.
1350 // REQUIRES: IsInfiniteDuration(d)
1352  return GetRepHi(d) < 0
1353  ? MakeDuration((std::numeric_limits<int64_t>::max)(), ~0U)
1354  : MakeDuration((std::numeric_limits<int64_t>::min)(), ~0U);
1355 }
1356 
1357 // Returns (-n)-1 (equivalently -(n+1)) without avoidable overflow.
1358 constexpr int64_t NegateAndSubtractOne(int64_t n) {
1359  // Note: Good compilers will optimize this expression to ~n when using
1360  // a two's-complement representation (which is required for int64_t).
1361  return (n < 0) ? -(n + 1) : (-n) - 1;
1362 }
1363 
1364 // Map between a Time and a Duration since the Unix epoch. Note that these
1365 // functions depend on the above mentioned choice of the Unix epoch for the
1366 // Time representation (and both need to be Time friends). Without this
1367 // knowledge, we would need to add-in/subtract-out UnixEpoch() respectively.
1368 constexpr Time FromUnixDuration(Duration d) { return Time(d); }
1369 constexpr Duration ToUnixDuration(Time t) { return t.rep_; }
1370 
1371 template <std::intmax_t N>
1372 constexpr Duration FromInt64(int64_t v, std::ratio<1, N>) {
1373  static_assert(0 < N && N <= 1000 * 1000 * 1000, "Unsupported ratio");
1374  // Subsecond ratios cannot overflow.
1375  return MakeNormalizedDuration(
1376  v / N, v % N * kTicksPerNanosecond * 1000 * 1000 * 1000 / N);
1377 }
1378 constexpr Duration FromInt64(int64_t v, std::ratio<60>) {
1379  return (v <= (std::numeric_limits<int64_t>::max)() / 60 &&
1380  v >= (std::numeric_limits<int64_t>::min)() / 60)
1381  ? MakeDuration(v * 60)
1382  : v > 0 ? InfiniteDuration() : -InfiniteDuration();
1383 }
1384 constexpr Duration FromInt64(int64_t v, std::ratio<3600>) {
1385  return (v <= (std::numeric_limits<int64_t>::max)() / 3600 &&
1386  v >= (std::numeric_limits<int64_t>::min)() / 3600)
1387  ? MakeDuration(v * 3600)
1388  : v > 0 ? InfiniteDuration() : -InfiniteDuration();
1389 }
1390 
1391 // IsValidRep64<T>(0) is true if the expression `int64_t{std::declval<T>()}` is
1392 // valid. That is, if a T can be assigned to an int64_t without narrowing.
1393 template <typename T>
1394 constexpr auto IsValidRep64(int)
1395  -> decltype(int64_t{std::declval<T>()}, bool()) {
1396  return true;
1397 }
1398 template <typename T>
1399 constexpr auto IsValidRep64(char) -> bool {
1400  return false;
1401 }
1402 
1403 // Converts a std::chrono::duration to an absl::Duration.
1404 template <typename Rep, typename Period>
1405 constexpr Duration FromChrono(const std::chrono::duration<Rep, Period>& d) {
1406  static_assert(IsValidRep64<Rep>(0), "duration::rep is invalid");
1407  return FromInt64(int64_t{d.count()}, Period{});
1408 }
1409 
1410 template <typename Ratio>
1411 int64_t ToInt64(Duration d, Ratio) {
1412  // Note: This may be used on MSVC, which may have a system_clock period of
1413  // std::ratio<1, 10 * 1000 * 1000>
1414  return ToInt64Seconds(d * Ratio::den / Ratio::num);
1415 }
1416 // Fastpath implementations for the 6 common duration units.
1417 inline int64_t ToInt64(Duration d, std::nano) {
1418  return ToInt64Nanoseconds(d);
1419 }
1420 inline int64_t ToInt64(Duration d, std::micro) {
1421  return ToInt64Microseconds(d);
1422 }
1423 inline int64_t ToInt64(Duration d, std::milli) {
1424  return ToInt64Milliseconds(d);
1425 }
1426 inline int64_t ToInt64(Duration d, std::ratio<1>) {
1427  return ToInt64Seconds(d);
1428 }
1429 inline int64_t ToInt64(Duration d, std::ratio<60>) {
1430  return ToInt64Minutes(d);
1431 }
1432 inline int64_t ToInt64(Duration d, std::ratio<3600>) {
1433  return ToInt64Hours(d);
1434 }
1435 
1436 // Converts an absl::Duration to a chrono duration of type T.
1437 template <typename T>
1439  using Rep = typename T::rep;
1440  using Period = typename T::period;
1441  static_assert(IsValidRep64<Rep>(0), "duration::rep is invalid");
1443  return d < ZeroDuration() ? (T::min)() : (T::max)();
1444  const auto v = ToInt64(d, Period{});
1445  if (v > (std::numeric_limits<Rep>::max)()) return (T::max)();
1446  if (v < (std::numeric_limits<Rep>::min)()) return (T::min)();
1447  return T{v};
1448 }
1449 
1450 } // namespace time_internal
1451 
1452 constexpr Duration Nanoseconds(int64_t n) {
1453  return time_internal::FromInt64(n, std::nano{});
1454 }
1455 constexpr Duration Microseconds(int64_t n) {
1456  return time_internal::FromInt64(n, std::micro{});
1457 }
1458 constexpr Duration Milliseconds(int64_t n) {
1459  return time_internal::FromInt64(n, std::milli{});
1460 }
1461 constexpr Duration Seconds(int64_t n) {
1462  return time_internal::FromInt64(n, std::ratio<1>{});
1463 }
1464 constexpr Duration Minutes(int64_t n) {
1465  return time_internal::FromInt64(n, std::ratio<60>{});
1466 }
1467 constexpr Duration Hours(int64_t n) {
1468  return time_internal::FromInt64(n, std::ratio<3600>{});
1469 }
1470 
1471 constexpr bool operator<(Duration lhs, Duration rhs) {
1474  : time_internal::GetRepHi(lhs) ==
1475  (std::numeric_limits<int64_t>::min)()
1476  ? time_internal::GetRepLo(lhs) + 1 <
1477  time_internal::GetRepLo(rhs) + 1
1478  : time_internal::GetRepLo(lhs) <
1480 }
1481 
1482 constexpr bool operator==(Duration lhs, Duration rhs) {
1483  return time_internal::GetRepHi(lhs) == time_internal::GetRepHi(rhs) &&
1485 }
1486 
1488  // This is a little interesting because of the special cases.
1489  //
1490  // If rep_lo_ is zero, we have it easy; it's safe to negate rep_hi_, we're
1491  // dealing with an integral number of seconds, and the only special case is
1492  // the maximum negative finite duration, which can't be negated.
1493  //
1494  // Infinities stay infinite, and just change direction.
1495  //
1496  // Finally we're in the case where rep_lo_ is non-zero, and we can borrow
1497  // a second's worth of ticks and avoid overflow (as negating int64_t-min + 1
1498  // is safe).
1499  return time_internal::GetRepLo(d) == 0
1500  ? time_internal::GetRepHi(d) ==
1501  (std::numeric_limits<int64_t>::min)()
1502  ? InfiniteDuration()
1511 }
1512 
1514  return time_internal::MakeDuration((std::numeric_limits<int64_t>::max)(),
1515  ~0U);
1516 }
1517 
1518 constexpr Duration FromChrono(const std::chrono::nanoseconds& d) {
1519  return time_internal::FromChrono(d);
1520 }
1521 constexpr Duration FromChrono(const std::chrono::microseconds& d) {
1522  return time_internal::FromChrono(d);
1523 }
1524 constexpr Duration FromChrono(const std::chrono::milliseconds& d) {
1525  return time_internal::FromChrono(d);
1526 }
1528  return time_internal::FromChrono(d);
1529 }
1530 constexpr Duration FromChrono(const std::chrono::minutes& d) {
1531  return time_internal::FromChrono(d);
1532 }
1533 constexpr Duration FromChrono(const std::chrono::hours& d) {
1534  return time_internal::FromChrono(d);
1535 }
1536 
1537 constexpr Time FromUnixNanos(int64_t ns) {
1539 }
1540 
1541 constexpr Time FromUnixMicros(int64_t us) {
1543 }
1544 
1545 constexpr Time FromUnixMillis(int64_t ms) {
1547 }
1548 
1549 constexpr Time FromUnixSeconds(int64_t s) {
1551 }
1552 
1553 constexpr Time FromTimeT(time_t t) {
1555 }
1556 
1557 } // namespace absl
1558 
1559 #endif // ABSL_TIME_TIME_H_
int v
Definition: variant_test.cc:81
constexpr int64_t kTicksPerNanosecond
Definition: time.h:98
friend bool operator!=(TimeZone a, TimeZone b)
Definition: time.h:989
CivilInfo At(Time t) const
Definition: time.cc:345
timespec ToTimespec(Duration d)
Definition: duration.cc:598
const char RFC1123_no_wday[]
Definition: time.h:1192
std::chrono::microseconds ToChronoMicroseconds(Duration d)
Definition: duration.cc:658
int64_t ToInt64Minutes(Duration d)
Definition: duration.cc:566
typename std::enable_if< std::is_floating_point< T >::value, int >::type EnableIfFloat
Definition: time.h:109
constexpr int64_t kTicksPerSecond
Definition: time.h:99
constexpr Duration FromInt64(int64_t v, std::ratio< 1, N >)
Definition: time.h:1372
double ToDoubleMinutes(Duration d)
Definition: duration.cc:591
absl::TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour, int min, int sec, TimeZone tz)
Definition: time.cc:396
Duration & operator/=(float r)
Definition: time.h:186
constexpr Time InfiniteFuture()
Definition: time.h:701
constexpr Time(Duration rep)
Definition: time.h:665
int64_t ToInt64(Duration d, Ratio)
Definition: time.h:1411
constexpr Duration Hours(int64_t n)
Definition: time.h:1467
Time & operator+=(Duration d)
Definition: time.h:604
time_zone fixed_time_zone(const seconds &offset)
std::string FormatTime(const std::string &format, absl::Time t, absl::TimeZone tz)
Definition: format.cc:70
bool operator<(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
absl::Time FromUniversal(int64_t universal)
Definition: time.cc:233
Duration DurationFromTimespec(timespec ts)
Definition: duration.cc:516
constexpr Duration(int64_t hi, uint32_t lo)
Definition: time.h:198
CivilHour ToCivilHour(Time t, TimeZone tz)
Definition: time.h:1060
CivilDay ToCivilDay(Time t, TimeZone tz)
Definition: time.h:1063
int64_t ToInt64Microseconds(Duration d)
Definition: duration.cc:544
uint128 operator-(uint128 lhs, uint128 rhs)
Definition: int128.h:662
constexpr Duration ToUnixDuration(Time t)
Definition: time.h:1369
TimeZone FixedTimeZone(int seconds)
Definition: time.h:1018
int64_t ToUnixMillis(Time t)
Definition: time.cc:257
std::string UnparseFlag(const T &v)
Definition: marshalling.h:254
typename std::enable_if< std::is_integral< T >::value||std::is_enum< T >::value, int >::type EnableIfIntegral
Definition: time.h:106
double ToDoubleMicroseconds(Duration d)
Definition: duration.cc:582
std::chrono::system_clock::time_point ToChronoTime(absl::Time t)
Definition: time.cc:333
int64_t ToUniversal(absl::Time t)
Definition: time.cc:278
const char RFC3339_full[]
Definition: time.h:1184
const char * zone_abbr
Definition: time.h:869
time_internal::cctz::detail::civil_time< time_internal::year_tag > CivilYear
Definition: civil_time.h:333
int64_t IDivDuration(bool satq, const Duration num, const Duration den, Duration *rem)
Definition: duration.cc:350
bool ParseTime(const std::string &format, const std::string &input, absl::Time *time, std::string *err)
Definition: format.cc:87
double ToDoubleSeconds(Duration d)
Definition: duration.cc:588
constexpr auto IsValidRep64(int) -> decltype(int64_t
Definition: time.h:1394
uint128 operator%(uint128 lhs, uint128 rhs)
Definition: int128.cc:165
TimeZone UTCTimeZone()
Definition: time.h:1026
constexpr Time FromUnixNanos(int64_t ns)
Definition: time.h:1537
std::chrono::minutes ToChronoMinutes(Duration d)
Definition: duration.cc:667
constexpr Time FromUnixMillis(int64_t ms)
Definition: time.h:1545
constexpr Duration Microseconds(int64_t n)
Definition: time.h:1455
Duration & operator/=(T r)
Definition: time.h:181
Duration Floor(const Duration d, const Duration unit)
Definition: duration.cc:502
int64_t ToUnixMicros(Time t)
Definition: time.cc:247
constexpr Duration()
Definition: time.h:153
time_internal::cctz::detail::civil_time< time_internal::hour_tag > CivilHour
Definition: civil_time.h:327
constexpr Time FromUnixDuration(Duration d)
Definition: time.h:1368
std::chrono::duration< std::int_fast64_t > seconds
Definition: time_zone.h:37
Definition: algorithm.h:29
constexpr Duration Milliseconds(int64_t n)
Definition: time.h:1458
uint128 operator*(uint128 lhs, uint128 rhs)
Definition: int128.h:671
cctz::time_point< cctz::seconds > sec
Definition: format.cc:38
constexpr Duration MakeNormalizedDuration(int64_t sec, int64_t ticks)
Definition: time.h:1337
bool operator>(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
absl::Time FromTM(const struct tm &tm, absl::TimeZone tz)
Definition: time.cc:428
Duration subsecond
Definition: time.h:630
constexpr Time FromUnixSeconds(int64_t s)
Definition: time.h:1549
constexpr Time UnixEpoch()
Definition: time.h:686
friend H AbslHashValue(H h, Time t)
Definition: time.h:652
timeval ToTimeval(Duration d)
Definition: duration.cc:628
int64_t ToInt64Nanoseconds(Duration d)
Definition: duration.cc:536
int64_t ToInt64Seconds(Duration d)
Definition: duration.cc:560
bool operator==(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
const char RFC3339_sec[]
Definition: time.h:1185
time_internal::cctz::detail::civil_time< time_internal::month_tag > CivilMonth
Definition: civil_time.h:331
constexpr int64_t NegateAndSubtractOne(int64_t n)
Definition: time.h:1358
bool operator>=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
constexpr Time FromUnixMicros(int64_t us)
Definition: time.h:1541
friend H AbslHashValue(H h, Duration d)
Definition: time.h:189
size_t value
uint128 operator+(uint128 lhs, uint128 rhs)
Definition: int128.h:653
bool operator!=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
CivilMonth ToCivilMonth(Time t, TimeZone tz)
Definition: time.h:1066
std::ostream & operator<<(std::ostream &os, CivilYear y)
Definition: civil_time.cc:62
CivilSecond cs
Definition: time.h:859
double ToUDate(Time t)
Definition: time.cc:273
int64_t ToInt64Hours(Duration d)
Definition: duration.cc:572
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
absl::Time TimeFromTimespec(timespec ts)
Definition: time.cc:282
Duration MakePosDoubleDuration(double n)
Definition: time.h:1324
double ToDoubleNanoseconds(Duration d)
Definition: duration.cc:579
constexpr Duration MakeDuration(int64_t hi, uint32_t lo)
Definition: time.h:1313
TimeZone(time_internal::cctz::time_zone tz)
Definition: time.h:841
char name[1]
Definition: mutex.cc:296
std::chrono::seconds ToChronoSeconds(Duration d)
Definition: duration.cc:664
constexpr Duration FromChrono(const std::chrono::duration< Rep, Period > &d)
Definition: time.h:1405
std::chrono::hours ToChronoHours(Duration d)
Definition: duration.cc:670
std::string FormatDuration(Duration d)
Definition: duration.cc:758
constexpr Duration Minutes(int64_t n)
Definition: time.h:1464
int64_t ToUnixSeconds(Time t)
Definition: time.cc:267
double ToDoubleMilliseconds(Duration d)
Definition: duration.cc:585
time_internal::cctz::detail::civil_time< time_internal::minute_tag > CivilMinute
Definition: civil_time.h:325
std::string name() const
Definition: time.h:850
friend std::ostream & operator<<(std::ostream &os, TimeZone tz)
Definition: time.h:990
Duration & operator*=(float r)
Definition: time.h:185
time_internal::cctz::detail::civil_time< time_internal::day_tag > CivilDay
Definition: civil_time.h:329
constexpr Time UniversalEpoch()
Definition: time.h:692
CivilSecond ToCivilSecond(Time t, TimeZone tz)
Definition: time.h:1054
std::chrono::milliseconds ToChronoMilliseconds(Duration d)
Definition: duration.cc:661
absl::Time FromUDate(double udate)
Definition: time.cc:229
CivilYear ToCivilYear(Time t, TimeZone tz)
Definition: time.h:1069
uint32_t rep_lo_
Definition: time.h:200
Duration rep_
Definition: time.h:666
std::chrono::time_point< std::chrono::system_clock, D > time_point
Definition: time_zone.h:36
int64_t ToInt64Milliseconds(Duration d)
Definition: duration.cc:552
constexpr uint32_t GetRepLo(Duration d)
Definition: time.h:1344
const char * zone_abbr
Definition: time.h:641
T ToChronoDuration(Duration d)
Definition: time.h:1438
bool ParseFlag(absl::string_view input, T *dst, std::string *error)
Definition: marshalling.h:240
double FDivDuration(Duration num, Duration den)
Definition: duration.cc:476
constexpr Duration Seconds(int64_t n)
Definition: time.h:1461
Time FromCivil(CivilSecond ct, TimeZone tz)
Definition: time.h:1085
Duration Trunc(Duration d, Duration unit)
Definition: duration.cc:498
const char RFC1123_full[]
Definition: time.h:1191
constexpr int64_t GetRepHi(Duration d)
Definition: time.h:1343
Duration DurationFromTimeval(timeval tv)
Definition: duration.cc:524
TimeZone LoadTimeZone(const std::string &name)
Definition: test_util.cc:29
constexpr Duration Nanoseconds(int64_t n)
Definition: time.h:1452
uint64_t b
Definition: layout_test.cc:50
uint128 operator/(uint128 lhs, uint128 rhs)
Definition: int128.cc:154
double ToDoubleHours(Duration d)
Definition: duration.cc:594
constexpr Duration OppositeInfinity(Duration d)
Definition: time.h:1351
time_t ToTimeT(Time t)
Definition: time.cc:271
Duration & operator*=(T r)
Definition: time.h:176
time_internal::cctz::time_zone cz_
Definition: time.h:994
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: utility.h:219
Duration AbsDuration(Duration d)
Definition: time.h:291
friend H AbslHashValue(H h, TimeZone tz)
Definition: time.h:983
constexpr Duration InfiniteDuration()
Definition: time.h:1513
bool load_time_zone(const std::string &name, time_zone *tz)
CivilMinute ToCivilMinute(Time t, TimeZone tz)
Definition: time.h:1057
Time FromDateTime(int64_t year, int mon, int day, int hour, int min, int sec, TimeZone tz)
Definition: time.h:1152
constexpr Duration ZeroDuration()
Definition: time.h:286
int64_t ToUnixNanos(Time t)
Definition: time.cc:237
int64_t rep_hi_
Definition: time.h:199
bool operator<=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
constexpr Time FromTimeT(time_t t)
Definition: time.h:1553
TimeZone LocalTimeZone()
Definition: time.h:1036
absl::Time TimeFromTimeval(timeval tv)
Definition: time.cc:286
constexpr Time InfinitePast()
Definition: time.h:709
friend bool operator==(TimeZone a, TimeZone b)
Definition: time.h:988
Duration Ceil(const Duration d, const Duration unit)
Definition: duration.cc:507
constexpr bool IsInfiniteDuration(Duration d)
Definition: time.h:1347
Time & operator-=(Duration d)
Definition: time.h:608
bool ParseDuration(const std::string &dur_string, Duration *d)
Definition: duration.cc:863
std::chrono::nanoseconds ToChronoNanoseconds(Duration d)
Definition: duration.cc:655


abseil_cpp
Author(s):
autogenerated on Tue Jun 18 2019 19:44:37