MCPcopy Create free account
hub / github.com/apache/impala / ToShortString

Method ToShortString

be/src/gutil/strings/human_readable.cc:276–323  ·  view source on GitHub ↗

Abbreviations used here are acceptable English abbreviations without the ending period (".") for brevity, except for uncommon abbreviations, in which case the entire word is spelled out. ("mo" and "mos" are not good abbreviations for "months" -- with or without the period). If needed, one can add a HumanReadableTime::ToStringShort() for shorter abbreviations or one for always spelling out the unit

Source from the content-addressed store, hash-verified

274// HumanReadableTime::ToStringShort() for shorter abbreviations or one
275// for always spelling out the unit, HumanReadableTime::ToStringLong().
276string HumanReadableElapsedTime::ToShortString(double seconds) {
277 string human_readable;
278
279 if (seconds < 0) {
280 human_readable = "-";
281 seconds = -seconds;
282 }
283
284 // Start with ns and keep going up to years.
285 if (seconds < 0.000001) {
286 StringAppendF(&human_readable, "%0.3g ns", seconds * 1000000000.0);
287 return human_readable;
288 }
289 if (seconds < 0.001) {
290 StringAppendF(&human_readable, "%0.3g us", seconds * 1000000.0);
291 return human_readable;
292 }
293 if (seconds < 1.0) {
294 StringAppendF(&human_readable, "%0.3g ms", seconds * 1000.0);
295 return human_readable;
296 }
297 if (seconds < 60.0) {
298 StringAppendF(&human_readable, "%0.3g s", seconds);
299 return human_readable;
300 }
301 seconds /= 60.0;
302 if (seconds < 60.0) {
303 StringAppendF(&human_readable, "%0.3g min", seconds);
304 return human_readable;
305 }
306 seconds /= 60.0;
307 if (seconds < 24.0) {
308 StringAppendF(&human_readable, "%0.3g h", seconds);
309 return human_readable;
310 }
311 seconds /= 24.0;
312 if (seconds < 30.0) {
313 StringAppendF(&human_readable, "%0.3g days", seconds);
314 return human_readable;
315 }
316 if (seconds < 365.2425) {
317 StringAppendF(&human_readable, "%0.3g months", seconds / 30.436875);
318 return human_readable;
319 }
320 seconds /= 365.2425;
321 StringAppendF(&human_readable, "%0.3g years", seconds);
322 return human_readable;
323}
324
325bool HumanReadableElapsedTime::ToDouble(const string& str, double* value) {
326 struct TimeUnits {

Callers

nothing calls this directly

Calls 1

StringAppendFFunction · 0.85

Tested by

no test coverage detected