Skip to content

Commit 3bddebd

Browse files
derekmaurocopybara-github
authored andcommitted
Add constexpr conversions from absl::Duration to int64_t
PiperOrigin-RevId: 736183575 Change-Id: I9c6b9317ce05b5ca45cbc5f75a985f1bbdaed043
1 parent eb4cff5 commit 3bddebd

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Diff for: absl/time/time.h

+14-12
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,12 @@ ABSL_ATTRIBUTE_CONST_FUNCTION Duration Hours(T n) {
620620
//
621621
// absl::Duration d = absl::Milliseconds(1500);
622622
// int64_t isec = absl::ToInt64Seconds(d); // isec == 1
623-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Nanoseconds(Duration d);
624-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Microseconds(Duration d);
625-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Milliseconds(Duration d);
626-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Seconds(Duration d);
627-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Minutes(Duration d);
628-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Hours(Duration d);
623+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Nanoseconds(Duration d);
624+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Microseconds(Duration d);
625+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Milliseconds(Duration d);
626+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Seconds(Duration d);
627+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Minutes(Duration d);
628+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Hours(Duration d);
629629

630630
// ToDoubleNanoseconds()
631631
// ToDoubleMicroseconds()
@@ -1864,7 +1864,7 @@ ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromTimeT(time_t t) {
18641864
return time_internal::FromUnixDuration(Seconds(t));
18651865
}
18661866

1867-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Nanoseconds(Duration d) {
1867+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Nanoseconds(Duration d) {
18681868
if (time_internal::GetRepHi(d) >= 0 &&
18691869
time_internal::GetRepHi(d) >> 33 == 0) {
18701870
return (time_internal::GetRepHi(d) * 1000 * 1000 * 1000) +
@@ -1873,7 +1873,8 @@ ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Nanoseconds(Duration d) {
18731873
return d / Nanoseconds(1);
18741874
}
18751875

1876-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Microseconds(Duration d) {
1876+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Microseconds(
1877+
Duration d) {
18771878
if (time_internal::GetRepHi(d) >= 0 &&
18781879
time_internal::GetRepHi(d) >> 43 == 0) {
18791880
return (time_internal::GetRepHi(d) * 1000 * 1000) +
@@ -1883,7 +1884,8 @@ ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Microseconds(Duration d) {
18831884
return d / Microseconds(1);
18841885
}
18851886

1886-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Milliseconds(Duration d) {
1887+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Milliseconds(
1888+
Duration d) {
18871889
if (time_internal::GetRepHi(d) >= 0 &&
18881890
time_internal::GetRepHi(d) >> 53 == 0) {
18891891
return (time_internal::GetRepHi(d) * 1000) +
@@ -1893,21 +1895,21 @@ ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Milliseconds(Duration d) {
18931895
return d / Milliseconds(1);
18941896
}
18951897

1896-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Seconds(Duration d) {
1898+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Seconds(Duration d) {
18971899
int64_t hi = time_internal::GetRepHi(d);
18981900
if (time_internal::IsInfiniteDuration(d)) return hi;
18991901
if (hi < 0 && time_internal::GetRepLo(d) != 0) ++hi;
19001902
return hi;
19011903
}
19021904

1903-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Minutes(Duration d) {
1905+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Minutes(Duration d) {
19041906
int64_t hi = time_internal::GetRepHi(d);
19051907
if (time_internal::IsInfiniteDuration(d)) return hi;
19061908
if (hi < 0 && time_internal::GetRepLo(d) != 0) ++hi;
19071909
return hi / 60;
19081910
}
19091911

1910-
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Hours(Duration d) {
1912+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t ToInt64Hours(Duration d) {
19111913
int64_t hi = time_internal::GetRepHi(d);
19121914
if (time_internal::IsInfiniteDuration(d)) return hi;
19131915
if (hi < 0 && time_internal::GetRepLo(d) != 0) ++hi;

0 commit comments

Comments
 (0)