Mercurial > minori
comparison src/core/time.cc @ 211:7cf53145de11
strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 07 Jan 2024 09:54:17 -0500 |
parents | 168382a89b21 |
children | 91ac90a34003 |
comparison
equal
deleted
inserted
replaced
200:da91af31ae73 | 211:7cf53145de11 |
---|---|
1 #include "core/time.h" | 1 #include "core/time.h" |
2 #include "core/strings.h" | |
3 | |
2 #include <cassert> | 4 #include <cassert> |
3 #include <cmath> | 5 #include <cmath> |
4 #include <cstdint> | 6 #include <cstdint> |
5 #include <ctime> | 7 #include <ctime> |
6 #include <string> | 8 #include <string> |
13 | 15 |
14 std::string Duration::AsRelativeString() { | 16 std::string Duration::AsRelativeString() { |
15 std::string result; | 17 std::string result; |
16 | 18 |
17 auto get = [](int64_t val, const std::string& s, const std::string& p) { | 19 auto get = [](int64_t val, const std::string& s, const std::string& p) { |
18 return std::to_string(val) + " " + (val == 1 ? s : p); | 20 return Strings::ToUtf8String(val) + " " + (val == 1 ? s : p); |
19 }; | 21 }; |
20 | 22 |
21 if (InSeconds() < 60) | 23 if (InSeconds() < 60) |
22 result = get(InSeconds(), "second", "seconds"); | 24 result = get(InSeconds(), "second", "seconds"); |
23 else if (InMinutes() < 60) | 25 else if (InMinutes() < 60) |