| 1 | // Aseprite | 
|---|
| 2 | // Copyright (C) 2017  David Capello | 
|---|
| 3 | // | 
|---|
| 4 | // This program is distributed under the terms of | 
|---|
| 5 | // the End-User License Agreement for Aseprite. | 
|---|
| 6 |  | 
|---|
| 7 | #ifdef HAVE_CONFIG_H | 
|---|
| 8 | #include "config.h" | 
|---|
| 9 | #endif | 
|---|
| 10 |  | 
|---|
| 11 | #include "app/util/readable_time.h" | 
|---|
| 12 |  | 
|---|
| 13 | #include <cstdio> | 
|---|
| 14 |  | 
|---|
| 15 | namespace app { | 
|---|
| 16 |  | 
|---|
| 17 | std::string human_readable_time(const int t) | 
|---|
| 18 | { | 
|---|
| 19 | char buf[32]; | 
|---|
| 20 | if (t < 900) | 
|---|
| 21 | std::sprintf(buf, "%dms", t); | 
|---|
| 22 | else if (t < 1000*59) | 
|---|
| 23 | std::sprintf(buf, "%0.2fs", double(t) / 1000.0); | 
|---|
| 24 | else if (t < 1000*60*59) | 
|---|
| 25 | std::sprintf(buf, "%0.2fm", double(t) / 1000.0 / 60.0); | 
|---|
| 26 | else | 
|---|
| 27 | std::sprintf(buf, "%0.2fh", double(t) / 1000.0 / 60.0 / 60.0); | 
|---|
| 28 | return buf; | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | } // namespace app | 
|---|
| 32 |  | 
|---|