62 #ifndef ABSL_TIME_TIME_H_ 63 #define ABSL_TIME_TIME_H_ 65 #if !defined(_MSC_VER) 76 #include <type_traits> 89 namespace time_internal {
90 int64_t
IDivDuration(
bool satq, Duration num, Duration den, Duration* rem);
93 constexpr int64_t
GetRepHi(Duration d);
94 constexpr uint32_t
GetRepLo(Duration d);
95 constexpr Duration
MakeDuration(int64_t hi, uint32_t lo);
100 template <std::
intmax_t N>
104 template <
typename T>
107 template <
typename T>
156 #if !defined(__clang__) && defined(_MSC_VER) && _MSC_VER < 1910 161 constexpr Duration(
const Duration& d) =
default;
163 Duration& operator=(
const Duration& d) =
default;
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);
175 template <
typename T>
180 template <
typename T>
185 Duration&
operator*=(
float r) {
return *
this *=
static_cast<double>(r); }
186 Duration&
operator/=(
float r) {
return *
this /=
static_cast<double>(r); }
188 template <
typename H>
198 constexpr
Duration(int64_t hi, uint32_t lo) : rep_hi_(hi), rep_lo_(lo) {}
217 template <
typename T>
221 template <
typename T>
225 template <
typename T>
399 template <
typename T, time_
internal::EnableIfFloat<T> = 0>
403 template <
typename T, time_
internal::EnableIfFloat<T> = 0>
407 template <
typename T, time_
internal::EnableIfFloat<T> = 0>
411 template <
typename T, time_
internal::EnableIfFloat<T> = 0>
423 template <
typename T, time_
internal::EnableIfFloat<T> = 0>
427 template <
typename T, time_
internal::EnableIfFloat<T> = 0>
597 constexpr
Time() =
default;
600 constexpr
Time(
const Time& t) =
default;
601 Time& operator=(
const Time& t) =
default;
651 template <
typename H>
808 bool ParseFlag(
const std::string& text,
Time* t, std::string* error);
850 std::string
name()
const {
return cz_.name(); }
982 template <
typename H>
991 return os << tz.
name();
1003 if (name ==
"localtime") {
1086 const auto ti = tz.
At(ct);
1172 struct tm ToTM(Time t, TimeZone tz);
1291 bool ParseTime(
const std::string&
format,
const std::string& input, Time* time,
1301 bool ParseTime(
const std::string& format,
const std::string& input, TimeZone tz,
1302 Time* time, std::string* err);
1308 namespace time_internal {
1325 const int64_t int_secs =
static_cast<int64_t
>(
n);
1326 const uint32_t ticks =
1353 ?
MakeDuration((std::numeric_limits<int64_t>::max)(), ~0U)
1354 :
MakeDuration((std::numeric_limits<int64_t>::min)(), ~0U);
1361 return (n < 0) ? -(n + 1) : (-n) - 1;
1371 template <std::
intmax_t N>
1373 static_assert(0 < N && N <= 1000 * 1000 * 1000,
"Unsupported ratio");
1379 return (v <= (std::numeric_limits<int64_t>::max)() / 60 &&
1380 v >= (std::numeric_limits<int64_t>::min)() / 60)
1385 return (v <= (std::numeric_limits<int64_t>::max)() / 3600 &&
1386 v >= (std::numeric_limits<int64_t>::min)() / 3600)
1393 template <
typename T>
1395 -> decltype(int64_t{std::declval<T>()},
bool()) {
1398 template <
typename T>
1404 template <
typename Rep,
typename Period>
1406 static_assert(IsValidRep64<Rep>(0),
"duration::rep is invalid");
1407 return FromInt64(int64_t{d.count()}, Period{});
1410 template <
typename Ratio>
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");
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)();
1475 (std::numeric_limits<int64_t>::min)()
1501 (std::numeric_limits<int64_t>::min)()
1559 #endif // ABSL_TIME_TIME_H_
constexpr int64_t kTicksPerNanosecond
friend bool operator!=(TimeZone a, TimeZone b)
timespec ToTimespec(Duration d)
const char RFC1123_no_wday[]
std::chrono::microseconds ToChronoMicroseconds(Duration d)
int64_t ToInt64Minutes(Duration d)
typename std::enable_if< std::is_floating_point< T >::value, int >::type EnableIfFloat
constexpr int64_t kTicksPerSecond
constexpr Duration FromInt64(int64_t v, std::ratio< 1, N >)
double ToDoubleMinutes(Duration d)
CivilInfo At(Time t) const
absl::TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour, int min, int sec, TimeZone tz)
Duration & operator/=(float r)
constexpr Time InfiniteFuture()
constexpr Time(Duration rep)
int64_t ToInt64(Duration d, Ratio)
constexpr Duration Hours(int64_t n)
Time & operator+=(Duration d)
time_zone fixed_time_zone(const seconds &offset)
std::string FormatTime(const std::string &format, absl::Time t, absl::TimeZone tz)
bool operator<(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
absl::Time FromUniversal(int64_t universal)
Duration DurationFromTimespec(timespec ts)
constexpr Duration(int64_t hi, uint32_t lo)
CivilHour ToCivilHour(Time t, TimeZone tz)
CivilDay ToCivilDay(Time t, TimeZone tz)
int64_t ToInt64Microseconds(Duration d)
uint128 operator-(uint128 lhs, uint128 rhs)
constexpr Duration ToUnixDuration(Time t)
TimeZone FixedTimeZone(int seconds)
int64_t ToUnixMillis(Time t)
std::string UnparseFlag(const T &v)
typename std::enable_if< std::is_integral< T >::value||std::is_enum< T >::value, int >::type EnableIfIntegral
double ToDoubleMicroseconds(Duration d)
std::chrono::system_clock::time_point ToChronoTime(absl::Time t)
int64_t ToUniversal(absl::Time t)
const char RFC3339_full[]
time_internal::cctz::detail::civil_time< time_internal::year_tag > CivilYear
int64_t IDivDuration(bool satq, const Duration num, const Duration den, Duration *rem)
bool ParseTime(const std::string &format, const std::string &input, absl::Time *time, std::string *err)
double ToDoubleSeconds(Duration d)
constexpr auto IsValidRep64(int) -> decltype(int64_t
uint128 operator%(uint128 lhs, uint128 rhs)
constexpr Time FromUnixNanos(int64_t ns)
std::chrono::minutes ToChronoMinutes(Duration d)
constexpr Time FromUnixMillis(int64_t ms)
constexpr Duration Microseconds(int64_t n)
Duration & operator/=(T r)
Duration Floor(const Duration d, const Duration unit)
int64_t ToUnixMicros(Time t)
time_internal::cctz::detail::civil_time< time_internal::hour_tag > CivilHour
constexpr Time FromUnixDuration(Duration d)
std::chrono::duration< std::int_fast64_t > seconds
constexpr Duration Milliseconds(int64_t n)
uint128 operator*(uint128 lhs, uint128 rhs)
constexpr Duration MakeNormalizedDuration(int64_t sec, int64_t ticks)
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)
constexpr Time FromUnixSeconds(int64_t s)
constexpr Time UnixEpoch()
friend H AbslHashValue(H h, Time t)
timeval ToTimeval(Duration d)
int64_t ToInt64Nanoseconds(Duration d)
int64_t ToInt64Seconds(Duration d)
bool operator==(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
time_zone local_time_zone()
time_internal::cctz::detail::civil_time< time_internal::month_tag > CivilMonth
constexpr int64_t NegateAndSubtractOne(int64_t n)
bool operator>=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
constexpr Time FromUnixMicros(int64_t us)
friend H AbslHashValue(H h, Duration d)
uint128 operator+(uint128 lhs, uint128 rhs)
bool operator!=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
CivilMonth ToCivilMonth(Time t, TimeZone tz)
std::ostream & operator<<(std::ostream &os, CivilYear y)
int64_t ToInt64Hours(Duration d)
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
absl::Time TimeFromTimespec(timespec ts)
Duration MakePosDoubleDuration(double n)
double ToDoubleNanoseconds(Duration d)
constexpr Duration MakeDuration(int64_t hi, uint32_t lo)
TimeZone(time_internal::cctz::time_zone tz)
std::chrono::seconds ToChronoSeconds(Duration d)
constexpr Duration FromChrono(const std::chrono::duration< Rep, Period > &d)
std::chrono::hours ToChronoHours(Duration d)
std::string FormatDuration(Duration d)
constexpr Duration Minutes(int64_t n)
int64_t ToUnixSeconds(Time t)
double ToDoubleMilliseconds(Duration d)
time_internal::cctz::detail::civil_time< time_internal::minute_tag > CivilMinute
friend std::ostream & operator<<(std::ostream &os, TimeZone tz)
Duration & operator*=(float r)
time_internal::cctz::detail::civil_time< time_internal::day_tag > CivilDay
constexpr Time UniversalEpoch()
CivilSecond ToCivilSecond(Time t, TimeZone tz)
std::chrono::milliseconds ToChronoMilliseconds(Duration d)
absl::Time FromUDate(double udate)
CivilYear ToCivilYear(Time t, TimeZone tz)
std::chrono::time_point< std::chrono::system_clock, D > time_point
int64_t ToInt64Milliseconds(Duration d)
constexpr uint32_t GetRepLo(Duration d)
T ToChronoDuration(Duration d)
bool ParseFlag(absl::string_view input, T *dst, std::string *error)
double FDivDuration(Duration num, Duration den)
constexpr Duration Seconds(int64_t n)
Time FromCivil(CivilSecond ct, TimeZone tz)
Duration Trunc(Duration d, Duration unit)
const char RFC1123_full[]
constexpr int64_t GetRepHi(Duration d)
time_zone utc_time_zone()
Duration DurationFromTimeval(timeval tv)
TimeZone LoadTimeZone(const std::string &name)
constexpr Duration Nanoseconds(int64_t n)
uint128 operator/(uint128 lhs, uint128 rhs)
double ToDoubleHours(Duration d)
constexpr Duration OppositeInfinity(Duration d)
Duration & operator*=(T r)
time_internal::cctz::time_zone cz_
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Duration AbsDuration(Duration d)
friend H AbslHashValue(H h, TimeZone tz)
constexpr Duration InfiniteDuration()
bool load_time_zone(const std::string &name, time_zone *tz)
CivilMinute ToCivilMinute(Time t, TimeZone tz)
Time FromDateTime(int64_t year, int mon, int day, int hour, int min, int sec, TimeZone tz)
constexpr Duration ZeroDuration()
int64_t ToUnixNanos(Time t)
bool operator<=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
constexpr Time FromTimeT(time_t t)
absl::Time TimeFromTimeval(timeval tv)
constexpr Time InfinitePast()
friend bool operator==(TimeZone a, TimeZone b)
Duration Ceil(const Duration d, const Duration unit)
constexpr bool IsInfiniteDuration(Duration d)
Time & operator-=(Duration d)
bool ParseDuration(const std::string &dur_string, Duration *d)
std::chrono::nanoseconds ToChronoNanoseconds(Duration d)