diff --git a/headers/os/locale/FloatFormat.h b/headers/os/locale/FloatFormat.h index 328dcdd1f8..d152eedf52 100644 --- a/headers/os/locale/FloatFormat.h +++ b/headers/os/locale/FloatFormat.h @@ -47,9 +47,6 @@ class BFloatFormat : public BNumberFormat, public BFloatFormatParameters { BFloatFormat &operator=(const BFloatFormat &other); BFloatFormat(BFloatFormatImpl *impl); // conceptually private - - private: - inline BFloatFormatImpl *FloatFormatImpl() const; }; diff --git a/headers/os/locale/Format.h b/headers/os/locale/Format.h index ccd13e19ff..05374c6460 100644 --- a/headers/os/locale/Format.h +++ b/headers/os/locale/Format.h @@ -40,9 +40,6 @@ class BFormat { BFormat &operator=(const BFormat &other); BFormat(); - - protected: - BFormatImpl *fImpl; }; #endif // _B_FORMAT_H_ diff --git a/headers/os/locale/IntegerFormat.h b/headers/os/locale/IntegerFormat.h index d9f8115a52..4f1e771f12 100644 --- a/headers/os/locale/IntegerFormat.h +++ b/headers/os/locale/IntegerFormat.h @@ -52,9 +52,6 @@ class BIntegerFormat : public BNumberFormat, public BIntegerFormatParameters { BIntegerFormat &operator=(const BIntegerFormat &other); BIntegerFormat(BIntegerFormatImpl *impl); // conceptually private - - private: - inline BIntegerFormatImpl *IntegerFormatImpl() const; }; diff --git a/headers/os/locale/NumberFormat.h b/headers/os/locale/NumberFormat.h index 0d19097c89..801c430750 100644 --- a/headers/os/locale/NumberFormat.h +++ b/headers/os/locale/NumberFormat.h @@ -14,9 +14,6 @@ class BNumberFormat : public BFormat { BNumberFormat &operator=(const BNumberFormat &other); BNumberFormat(); - - private: - inline BNumberFormatImpl *NumberFormatImpl() const; }; diff --git a/headers/private/locale/ICUWrapper.h b/headers/private/locale/ICUWrapper.h index 5667c3dcbb..e5e1a6aa49 100644 --- a/headers/private/locale/ICUWrapper.h +++ b/headers/private/locale/ICUWrapper.h @@ -13,6 +13,7 @@ #include #include +#include /* Convert UnicodeString to BString needs an ICU ByteSink to do the work */ diff --git a/src/apps/aboutsystem/AboutSystem.cpp b/src/apps/aboutsystem/AboutSystem.cpp index 13d0ec8512..f704773395 100644 --- a/src/apps/aboutsystem/AboutSystem.cpp +++ b/src/apps/aboutsystem/AboutSystem.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -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; } diff --git a/src/kits/locale/FloatFormat.cpp b/src/kits/locale/FloatFormat.cpp index a35162594e..174e967182 100644 --- a/src/kits/locale/FloatFormat.cpp +++ b/src/kits/locale/FloatFormat.cpp @@ -17,9 +17,7 @@ BFloatFormat::~BFloatFormat() status_t BFloatFormat::Format(double number, BString *buffer) const { - if (!fImpl) - return B_NO_INIT; - return FloatFormatImpl()->Format(this, number, buffer); + return B_ERROR; } // Format @@ -28,10 +26,7 @@ BFloatFormat::Format(double number, BString *buffer, format_field_position *positions, int32 positionCount, int32 *fieldCount, bool allFieldPositions) const { - if (!fImpl) - return B_NO_INIT; - return FloatFormatImpl()->Format(this,number, buffer, positions, - positionCount, fieldCount, allFieldPositions); + return B_ERROR; } // = @@ -51,11 +46,3 @@ BFloatFormat::BFloatFormat(BFloatFormatImpl *impl) { } -// FloatFormatImpl -inline -BFloatFormatImpl * -BFloatFormat::FloatFormatImpl() const -{ - return static_cast(fImpl); -} - diff --git a/src/kits/locale/Format.cpp b/src/kits/locale/Format.cpp index 4e7654143c..9d42141dfe 100644 --- a/src/kits/locale/Format.cpp +++ b/src/kits/locale/Format.cpp @@ -3,7 +3,6 @@ // copy constructor BFormat::BFormat(const BFormat &other) - : fImpl(other.fImpl) { } @@ -16,7 +15,6 @@ BFormat::~BFormat() BFormat & BFormat::operator=(const BFormat &other) { - fImpl = other.fImpl; return *this; } diff --git a/src/kits/locale/IntegerFormat.cpp b/src/kits/locale/IntegerFormat.cpp index b6d954c243..3a702c5df0 100644 --- a/src/kits/locale/IntegerFormat.cpp +++ b/src/kits/locale/IntegerFormat.cpp @@ -17,9 +17,7 @@ BIntegerFormat::~BIntegerFormat() status_t BIntegerFormat::Format(int64 number, BString *buffer) const { - if (!fImpl) - return B_NO_INIT; - return IntegerFormatImpl()->Format(this, number, buffer); + return B_ERROR; } // Format @@ -28,10 +26,7 @@ BIntegerFormat::Format(int64 number, BString *buffer, format_field_position *positions, int32 positionCount, int32 *fieldCount, bool allFieldPositions) const { - if (!fImpl) - return B_NO_INIT; - return IntegerFormatImpl()->Format(this,number, buffer, positions, - positionCount, fieldCount, allFieldPositions); + return B_ERROR; } // = @@ -51,11 +46,3 @@ BIntegerFormat::BIntegerFormat(BIntegerFormatImpl *impl) { } -// IntegerFormatImpl -inline -BIntegerFormatImpl * -BIntegerFormat::IntegerFormatImpl() const -{ - return static_cast(fImpl); -} - diff --git a/src/kits/locale/NumberFormat.cpp b/src/kits/locale/NumberFormat.cpp index 48001cd12f..40b1e1e77f 100644 --- a/src/kits/locale/NumberFormat.cpp +++ b/src/kits/locale/NumberFormat.cpp @@ -26,11 +26,3 @@ BNumberFormat::BNumberFormat() { } -// NumberFormatImpl -inline -BNumberFormatImpl * -BNumberFormat::NumberFormatImpl() const -{ - return static_cast(fImpl); -} - diff --git a/src/kits/locale/TimeFormat.cpp b/src/kits/locale/TimeFormat.cpp index eada59cd35..82ed3c4bc4 100644 --- a/src/kits/locale/TimeFormat.cpp +++ b/src/kits/locale/TimeFormat.cpp @@ -14,24 +14,75 @@ status_t BTimeFormat::Format(int64 number, BString* buffer) const { // create time unit amount instance - a combination of Number and time unit UErrorCode status = U_ZERO_ERROR; - TimeUnitAmount* source = new TimeUnitAmount(number/1000000, TimeUnit::UTIMEUNIT_SECOND, status); - // create time unit format instance + + int64 days, hours, minutes, seconds, remainder; + + days = number / (24 * 3600); + remainder = number % (24 * 3600); + + hours = remainder / 3600; + remainder %= 3600; + + minutes = remainder / 60; + remainder %= 60; + + seconds = remainder; + TimeUnitFormat* format = new TimeUnitFormat(status); - // format a time unit amount UnicodeString formatted; - Formattable formattable(source); + Formattable formattable; + BStringByteSink bbs(buffer); + if (!U_SUCCESS(status)) { - delete source; delete format; return B_ERROR; } - formatted = ((icu_4_2::Format*)format)->format(formattable, formatted, status); + if (days) { + TimeUnitAmount* daysAmount = new TimeUnitAmount(days, + TimeUnit::UTIMEUNIT_DAY, status); - BStringByteSink bbs(buffer); + formattable.adoptObject(daysAmount); + formatted = ((icu_4_2::Format*)format)->format(formattable, formatted, + status); + } + + if (hours) { + TimeUnitAmount* hoursAmount = new TimeUnitAmount(hours, + TimeUnit::UTIMEUNIT_HOUR, status); + + formattable.adoptObject(hoursAmount); + if (days) + formatted.append(", "); + formatted = ((icu_4_2::Format*)format)->format(formattable, formatted, + status); + } + + if (minutes) { + TimeUnitAmount* minutesAmount = new TimeUnitAmount(minutes, + TimeUnit::UTIMEUNIT_MINUTE, status); + + formattable.adoptObject(minutesAmount); + if (days || hours) + formatted.append(", "); + formatted = ((icu_4_2::Format*)format)->format(formattable, formatted, + status); + } + + + if (seconds || (minutes == 0 && hours == 0 && days == 0)) { + TimeUnitAmount* secondsAmount = new TimeUnitAmount(seconds, + TimeUnit::UTIMEUNIT_SECOND, status); + + formattable.adoptObject(secondsAmount); + if (days || hours || minutes) + formatted.append(", "); + formatted = ((icu_4_2::Format*)format)->format(formattable, formatted, + status); + } formatted.toUTF8(bbs); - delete source; + delete format; return B_OK; } diff --git a/src/tests/kits/locale/formatTest.cpp b/src/tests/kits/locale/formatTest.cpp index 7dd7dc8c28..203429f58c 100644 --- a/src/tests/kits/locale/formatTest.cpp +++ b/src/tests/kits/locale/formatTest.cpp @@ -5,11 +5,17 @@ #include #include -int main() { +int +main() +{ BTimeFormat timeFormatter; BString str; - timeFormatter.Format(123456, &str); + if (timeFormatter.Format(123456, &str) != B_OK) { + std::cout << "Conversion error\n"; + return -1; + } - std::cout << str.String(); + std::cout << str.String() << std::endl; + return 0; }