@@ -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 int64_t ToInt64Nanoseconds (Duration d);
624- ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Microseconds (Duration d);
625- ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Milliseconds (Duration d);
626- ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Seconds (Duration d);
627- ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Minutes (Duration d);
628- ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Hours (Duration d);
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);
629629
630630// ToDoubleNanoseconds()
631631// ToDoubleMicroseconds()
@@ -1864,6 +1864,56 @@ 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) {
1868+ if (time_internal::GetRepHi (d) >= 0 &&
1869+ time_internal::GetRepHi (d) >> 33 == 0 ) {
1870+ return (time_internal::GetRepHi (d) * 1000 * 1000 * 1000 ) +
1871+ (time_internal::GetRepLo (d) / time_internal::kTicksPerNanosecond );
1872+ }
1873+ return d / Nanoseconds (1 );
1874+ }
1875+
1876+ ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Microseconds (Duration d) {
1877+ if (time_internal::GetRepHi (d) >= 0 &&
1878+ time_internal::GetRepHi (d) >> 43 == 0 ) {
1879+ return (time_internal::GetRepHi (d) * 1000 * 1000 ) +
1880+ (time_internal::GetRepLo (d) /
1881+ (time_internal::kTicksPerNanosecond * 1000 ));
1882+ }
1883+ return d / Microseconds (1 );
1884+ }
1885+
1886+ ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Milliseconds (Duration d) {
1887+ if (time_internal::GetRepHi (d) >= 0 &&
1888+ time_internal::GetRepHi (d) >> 53 == 0 ) {
1889+ return (time_internal::GetRepHi (d) * 1000 ) +
1890+ (time_internal::GetRepLo (d) /
1891+ (time_internal::kTicksPerNanosecond * 1000 * 1000 ));
1892+ }
1893+ return d / Milliseconds (1 );
1894+ }
1895+
1896+ ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Seconds (Duration d) {
1897+ int64_t hi = time_internal::GetRepHi (d);
1898+ if (time_internal::IsInfiniteDuration (d)) return hi;
1899+ if (hi < 0 && time_internal::GetRepLo (d) != 0 ) ++hi;
1900+ return hi;
1901+ }
1902+
1903+ ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Minutes (Duration d) {
1904+ int64_t hi = time_internal::GetRepHi (d);
1905+ if (time_internal::IsInfiniteDuration (d)) return hi;
1906+ if (hi < 0 && time_internal::GetRepLo (d) != 0 ) ++hi;
1907+ return hi / 60 ;
1908+ }
1909+
1910+ ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64Hours (Duration d) {
1911+ int64_t hi = time_internal::GetRepHi (d);
1912+ if (time_internal::IsInfiniteDuration (d)) return hi;
1913+ if (hi < 0 && time_internal::GetRepLo (d) != 0 ) ++hi;
1914+ return hi / (60 * 60 );
1915+ }
1916+
18671917ABSL_NAMESPACE_END
18681918} // namespace absl
18691919
0 commit comments