| 87 | } |
| 88 | |
| 89 | absl::StatusOr<absl::string_view> FormatDuration( |
| 90 | const Value& value, std::string& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
| 91 | absl::Duration duration = value.GetDuration(); |
| 92 | if (duration == absl::ZeroDuration()) { |
| 93 | return "0s"; |
| 94 | } |
| 95 | if (duration < absl::ZeroDuration()) { |
| 96 | scratch.append("-"); |
| 97 | duration = absl::AbsDuration(duration); |
| 98 | } |
| 99 | int64_t seconds = absl::ToInt64Seconds(duration); |
| 100 | absl::StrAppend(&scratch, seconds); |
| 101 | int64_t nanos = absl::ToInt64Nanoseconds(duration - absl::Seconds(seconds)); |
| 102 | if (nanos != 0) { |
| 103 | scratch.append("."); |
| 104 | if (nanos % kNanosPerMillisecond == 0) { |
| 105 | scratch.append(absl::StrFormat("%03d", nanos / kNanosPerMillisecond)); |
| 106 | } else if (nanos % kNanosPerMicrosecond == 0) { |
| 107 | scratch.append(absl::StrFormat("%06d", nanos / kNanosPerMicrosecond)); |
| 108 | } else { |
| 109 | scratch.append(absl::StrFormat("%09d", nanos)); |
| 110 | } |
| 111 | } |
| 112 | scratch.append("s"); |
| 113 | return scratch; |
| 114 | } |
| 115 | |
| 116 | absl::StatusOr<absl::string_view> FormatDouble( |
| 117 | double value, std::optional<int> precision, bool use_scientific_notation, |