| 1038 | } |
| 1039 | |
| 1040 | String Utility::FormatDuration(double duration) |
| 1041 | { |
| 1042 | std::vector<String> tokens; |
| 1043 | String result; |
| 1044 | |
| 1045 | if (duration >= 86400) { |
| 1046 | int days = duration / 86400; |
| 1047 | tokens.emplace_back(Convert::ToString(days) + (days != 1 ? " days" : " day")); |
| 1048 | duration = static_cast<int>(duration) % 86400; |
| 1049 | } |
| 1050 | |
| 1051 | if (duration >= 3600) { |
| 1052 | int hours = duration / 3600; |
| 1053 | tokens.emplace_back(Convert::ToString(hours) + (hours != 1 ? " hours" : " hour")); |
| 1054 | duration = static_cast<int>(duration) % 3600; |
| 1055 | } |
| 1056 | |
| 1057 | if (duration >= 60) { |
| 1058 | int minutes = duration / 60; |
| 1059 | tokens.emplace_back(Convert::ToString(minutes) + (minutes != 1 ? " minutes" : " minute")); |
| 1060 | duration = static_cast<int>(duration) % 60; |
| 1061 | } |
| 1062 | |
| 1063 | if (duration >= 1) { |
| 1064 | int seconds = duration; |
| 1065 | tokens.emplace_back(Convert::ToString(seconds) + (seconds != 1 ? " seconds" : " second")); |
| 1066 | } |
| 1067 | |
| 1068 | if (tokens.size() == 0) { |
| 1069 | int milliseconds = std::floor(duration * 1000); |
| 1070 | if (milliseconds >= 1) |
| 1071 | tokens.emplace_back(Convert::ToString(milliseconds) + (milliseconds != 1 ? " milliseconds" : " millisecond")); |
| 1072 | else |
| 1073 | tokens.emplace_back("less than 1 millisecond"); |
| 1074 | } |
| 1075 | |
| 1076 | return NaturalJoin(tokens); |
| 1077 | } |
| 1078 | |
| 1079 | String Utility::FormatDateTime(const char* format, double ts) |
| 1080 | { |