* Improve the test for TimeFormat (style and error checking)

* Fix the TimeFormat API, there was a double free. Make it work as expected : you send it a number of seconds and it will format it properly in days, hours, minutes, seconds with proper plural.
 * Cleanup other parts of the Format API from useless things. They may get reintroduced later if we feel the need to do so.
 * AboutSystem now use TimeFormat to display the uptime in properly localized way.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35506 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues
2010-02-17 15:35:28 +00:00
parent 03bab65450
commit 33eead339b
12 changed files with 79 additions and 120 deletions
+6 -57
View File
@@ -34,6 +34,7 @@
#include <ScrollView.h>
#include <String.h>
#include <StringView.h>
#include <TimeFormat.h>
#include <TranslationUtils.h>
#include <TranslatorFormats.h>
#include <View.h>
@@ -1530,64 +1531,12 @@ MemUsageToString(char string[], size_t size, system_info* info)
static const char*
UptimeToString(char string[], size_t size)
{
int64 days, hours, minutes, seconds, remainder;
int64 systime = system_time();
BTimeFormat formatter;
BString str;
days = systime / 86400000000LL;
remainder = systime % 86400000000LL;
hours = remainder / 3600000000LL;
remainder = remainder % 3600000000LL;
minutes = remainder / 60000000;
remainder = remainder % 60000000;
seconds = remainder / 1000000;
char* str = string;
if (days) {
if (days > 1) {
str += snprintf(str, size, TR("%lld days"), days);
} else {
str += snprintf(str, size, TR("%lld day"), days);
}
}
if (hours) {
if (hours > 1) {
str += snprintf(str, size - strlen(string),
TR("%s%lld hours"),
str != string ? ", " : "", hours);
} else {
str += snprintf(str, size - strlen(string),
TR("%s%lld hour"),
str != string ? ", " : "", hours);
}
}
if (minutes) {
if (minutes > 1) {
str += snprintf(str, size - strlen(string),
TR("%s%lld minutes"),
str != string ? ", " : "", minutes);
} else {
str += snprintf(str, size - strlen(string),
TR("%s%lld minute"),
str != string ? ", " : "", minutes);
}
}
if (seconds || str == string) {
// Haiku would be well-known to boot very fast.
// Let's be ready to handle below minute uptime, zero second included ;-)
if (seconds > 1) {
str += snprintf(str, size - strlen(string),
TR("%s%lld seconds"),
str != string ? ", " : "", seconds);
} else {
str += snprintf(str, size - strlen(string),
TR("%s%lld second"),
str != string ? ", " : "", seconds);
}
}
formatter.Format(system_time() / 1000000, &str);
str.CopyInto(string,0,size);
string[str.Length()] = '\0';
return string;
}