Sebastian Jansson | 30bd403 | 2018-04-13 11:56:17 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Sebastian Jansson | 6fae6ec | 2018-05-08 08:43:18 | [diff] [blame] | 11 | #include "api/units/timestamp.h" |
Sebastian Jansson | 30bd403 | 2018-04-13 11:56:17 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 13 | #include "api/array_view.h" |
Sebastian Jansson | 30bd403 | 2018-04-13 11:56:17 | [diff] [blame] | 14 | #include "rtc_base/strings/string_builder.h" |
| 15 | |
| 16 | namespace webrtc { |
Sebastian Jansson | 72bba62 | 2018-11-19 10:17:12 | [diff] [blame] | 17 | std::string ToString(Timestamp value) { |
Sebastian Jansson | 30bd403 | 2018-04-13 11:56:17 | [diff] [blame] | 18 | char buf[64]; |
| 19 | rtc::SimpleStringBuilder sb(buf); |
Sebastian Jansson | bd7ed4b | 2019-03-05 08:14:02 | [diff] [blame] | 20 | if (value.IsPlusInfinity()) { |
| 21 | sb << "+inf ms"; |
| 22 | } else if (value.IsMinusInfinity()) { |
| 23 | sb << "-inf ms"; |
Sebastian Jansson | 30bd403 | 2018-04-13 11:56:17 | [diff] [blame] | 24 | } else { |
Sebastian Jansson | bae1275 | 2019-11-05 12:25:47 | [diff] [blame] | 25 | if (value.us() == 0 || (value.us() % 1000) != 0) |
| 26 | sb << value.us() << " us"; |
| 27 | else if (value.ms() % 1000 != 0) |
Sebastian Jansson | 2afd281 | 2018-08-23 12:44:05 | [diff] [blame] | 28 | sb << value.ms() << " ms"; |
Sebastian Jansson | bae1275 | 2019-11-05 12:25:47 | [diff] [blame] | 29 | else |
| 30 | sb << value.seconds() << " s"; |
Sebastian Jansson | 30bd403 | 2018-04-13 11:56:17 | [diff] [blame] | 31 | } |
| 32 | return sb.str(); |
| 33 | } |
| 34 | } // namespace webrtc |