From 2a5e33a98056c2b92d46a6c9aae6da808c8524b1 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 26 Sep 2014 18:24:07 +0200 Subject: [PATCH] Move date formatting from BLocale to BDateFormat * There is a little code duplication. This will be moved to BFormat once the time and datetime formatting is also moved out of BLocale * The way to create a BDateFormat from a BLocale is still open for discussion. I'm undecided between making BDateFormat a member of BLocale, or adding a BDateFormat(const BLocale&) constructor. * Adjust all users of the API. --- headers/os/locale/DateFormat.h | 54 +++- headers/os/locale/DateTimeFormat.h | 16 +- headers/os/locale/Locale.h | 48 +-- headers/os/locale/LocaleRoster.h | 2 + headers/private/locale/LocaleRosterData.h | 2 + headers/private/shared/CalendarView.h | 1 + src/apps/deskbar/TimeView.cpp | 3 +- src/kits/locale/DateFormat.cpp | 276 +++++++++++++++++- src/kits/locale/Locale.cpp | 222 +------------- src/kits/locale/LocaleRoster.cpp | 8 + src/kits/locale/LocaleRosterData.cpp | 1 + src/kits/shared/CalendarView.cpp | 2 +- src/kits/tracker/WidgetAttributeText.cpp | 3 +- src/preferences/locale/FormatSettingsView.cpp | 9 +- src/preferences/time/DateTimeEdit.cpp | 5 +- src/preferences/time/TimeZoneListView.cpp | 3 +- 16 files changed, 366 insertions(+), 289 deletions(-) diff --git a/headers/os/locale/DateFormat.h b/headers/os/locale/DateFormat.h index 2aee302a34..31dbbc27f0 100644 --- a/headers/os/locale/DateFormat.h +++ b/headers/os/locale/DateFormat.h @@ -1,29 +1,67 @@ /* - * Copyright 2010, Haiku, Inc. + * Copyright 2010-2014, Haiku, Inc. * Distributed under the terms of the MIT Licence. */ #ifndef _B_DATE_FORMAT_H_ #define _B_DATE_FORMAT_H_ + #include +#include +#include +#include class BString; +class BTimeZone; -class BDateFormat : public BDateTimeFormat { + +enum BWeekday { + B_WEEKDAY_MONDAY = 1, + B_WEEKDAY_TUESDAY, + B_WEEKDAY_WEDNESDAY, + B_WEEKDAY_THURSDAY, + B_WEEKDAY_FRIDAY, + B_WEEKDAY_SATURDAY, + B_WEEKDAY_SUNDAY, +}; + + +class BDateFormat { public: - BDateFormat(); + BDateFormat(const BLanguage* const, + const BFormattingConventions* const); BDateFormat(const BDateFormat &other); virtual ~BDateFormat(); + static const BDateFormat* Default(); + // formatting - // no-frills version: Simply appends the - // formatted date to the string buffer. - // Can fail only with B_NO_MEMORY or B_BAD_VALUE. - virtual status_t Format(bigtime_t value, BString* buffer) const; + ssize_t Format(char* string, size_t maxSize, + time_t time, BDateFormatStyle style) const; + status_t Format(BString* string, time_t time, + BDateFormatStyle style, + const BTimeZone* timeZone = NULL) const; + status_t Format(BString* string, + int*& fieldPositions, int& fieldCount, + time_t time, BDateFormatStyle style) const; - // TODO: ... all, basically! + status_t GetFields(BDateElement*& fields, + int& fieldCount, BDateFormatStyle style + ) const; + + status_t GetStartOfWeek(BWeekday* weekday) const; + + // TODO parsing + +private: + icu::DateFormat* _CreateDateFormatter( + const BString& format) const; + + mutable BLocker fLock; + BFormattingConventions fConventions; + BLanguage fLanguage; }; diff --git a/headers/os/locale/DateTimeFormat.h b/headers/os/locale/DateTimeFormat.h index 3c3a9f7ef0..f423673322 100644 --- a/headers/os/locale/DateTimeFormat.h +++ b/headers/os/locale/DateTimeFormat.h @@ -1,16 +1,30 @@ /* - * Copyright 2010, Haiku, Inc. + * Copyright 2010-2014, Haiku, Inc. * Distributed under the terms of the MIT Licence. */ #ifndef _B_DATE_TIME_FORMAT_H_ #define _B_DATE_TIME_FORMAT_H_ + #include #include class BString; + +enum BDateElement { + B_DATE_ELEMENT_INVALID = B_BAD_DATA, + B_DATE_ELEMENT_YEAR = 0, + B_DATE_ELEMENT_MONTH, + B_DATE_ELEMENT_DAY, + B_DATE_ELEMENT_AM_PM, + B_DATE_ELEMENT_HOUR, + B_DATE_ELEMENT_MINUTE, + B_DATE_ELEMENT_SECOND +}; + + class BDateTimeFormat : public BFormat { public: BDateTimeFormat(); diff --git a/headers/os/locale/Locale.h b/headers/os/locale/Locale.h index febdc25325..e4c26cf5b3 100644 --- a/headers/os/locale/Locale.h +++ b/headers/os/locale/Locale.h @@ -7,6 +7,7 @@ #include +#include #include #include #include @@ -18,21 +19,11 @@ namespace icu { class BCatalog; +class BDateFormat; class BString; class BTimeZone; -enum BDateElement { - B_DATE_ELEMENT_INVALID = B_BAD_DATA, - B_DATE_ELEMENT_YEAR = 0, - B_DATE_ELEMENT_MONTH, - B_DATE_ELEMENT_DAY, - B_DATE_ELEMENT_AM_PM, - B_DATE_ELEMENT_HOUR, - B_DATE_ELEMENT_MINUTE, - B_DATE_ELEMENT_SECOND -}; - enum BNumberElement { B_NUMBER_ELEMENT_INVALID = B_BAD_DATA, B_NUMBER_ELEMENT_INTEGER = 0, @@ -41,18 +32,6 @@ enum BNumberElement { }; -// TODO: move this to BCalendar (should we ever have that) or BDate -enum BWeekday { - B_WEEKDAY_MONDAY = 1, - B_WEEKDAY_TUESDAY, - B_WEEKDAY_WEDNESDAY, - B_WEEKDAY_THURSDAY, - B_WEEKDAY_FRIDAY, - B_WEEKDAY_SATURDAY, - B_WEEKDAY_SUNDAY, -}; - - class BLocale { public: BLocale(const BLanguage* language = NULL, @@ -78,11 +57,6 @@ public: // see definitions in LocaleStrings.h const char* GetString(uint32 id) const; - void FormatString(char* target, size_t maxSize, - char* fmt, ...) const; - void FormatString(BString* buffer, char* fmt, - ...) const; - // DateTime // TODO: drop some of these once BDateTimeFormat @@ -95,24 +69,6 @@ public: BTimeFormatStyle timeStyle, const BTimeZone* timeZone = NULL) const; - // Date - - // TODO: drop some of these once BDateFormat - // has been implemented! - ssize_t FormatDate(char* string, size_t maxSize, - time_t time, BDateFormatStyle style) const; - status_t FormatDate(BString* string, time_t time, - BDateFormatStyle style, - const BTimeZone* timeZone = NULL) const; - status_t FormatDate(BString* string, - int*& fieldPositions, int& fieldCount, - time_t time, BDateFormatStyle style) const; - status_t GetDateFields(BDateElement*& fields, - int& fieldCount, BDateFormatStyle style - ) const; - - status_t GetStartOfWeek(BWeekday* weekday) const; - // Time // TODO: drop some of these once BTimeFormat diff --git a/headers/os/locale/LocaleRoster.h b/headers/os/locale/LocaleRoster.h index e4ecb1335f..c0a7fd12a1 100644 --- a/headers/os/locale/LocaleRoster.h +++ b/headers/os/locale/LocaleRoster.h @@ -16,6 +16,7 @@ class BBitmap; class BCatalog; class BCollator; class BCountry; +class BDateFormat; class BFormattingConventions; class BLanguage; class BLocale; @@ -78,6 +79,7 @@ public: // (that needs to link with liblocalestub.a) const BLocale* GetDefaultLocale() const; + const BDateFormat* GetDefaultDateFormat() const; bool IsFilesystemTranslationPreferred() const; diff --git a/headers/private/locale/LocaleRosterData.h b/headers/private/locale/LocaleRosterData.h index 6e84bde01b..599642cce2 100644 --- a/headers/private/locale/LocaleRosterData.h +++ b/headers/private/locale/LocaleRosterData.h @@ -7,6 +7,7 @@ #include +#include #include #include #include @@ -37,6 +38,7 @@ struct LocaleRosterData { BLocale fDefaultLocale; BTimeZone fDefaultTimeZone; + BDateFormat fDefaultDateFormat; bool fIsFilesystemTranslationPreferred; diff --git a/headers/private/shared/CalendarView.h b/headers/private/shared/CalendarView.h index 04a0efeed5..292c22f8f2 100644 --- a/headers/private/shared/CalendarView.h +++ b/headers/private/shared/CalendarView.h @@ -9,6 +9,7 @@ #include "DateTime.h" +#include #include #include #include diff --git a/src/apps/deskbar/TimeView.cpp b/src/apps/deskbar/TimeView.cpp index 8559fe8103..9bbb9d8283 100644 --- a/src/apps/deskbar/TimeView.cpp +++ b/src/apps/deskbar/TimeView.cpp @@ -40,6 +40,7 @@ All rights reserved. #include #include +#include #include #include #include @@ -421,7 +422,7 @@ TTimeView::GetCurrentDate() { char tmp[sizeof(fCurrentDateStr)]; - fLocale.FormatDate(tmp, sizeof(fCurrentDateStr), fCurrentTime, + BDateFormat::Default()->Format(tmp, sizeof(fCurrentDateStr), fCurrentTime, B_FULL_DATE_FORMAT); // remove leading 0 from date when month is less than 10 (MM/DD/YY) diff --git a/src/kits/locale/DateFormat.cpp b/src/kits/locale/DateFormat.cpp index 3377049362..08a80c2b9f 100644 --- a/src/kits/locale/DateFormat.cpp +++ b/src/kits/locale/DateFormat.cpp @@ -8,27 +8,291 @@ #include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + // default constructor -BDateFormat::BDateFormat() - : BDateTimeFormat() +BDateFormat::BDateFormat(const BLanguage* const language, + const BFormattingConventions* const conventions) { + if (conventions != NULL) + fConventions = *conventions; + else + BLocale::Default()->GetFormattingConventions(&fConventions); + + if (language != NULL) + fLanguage = *language; + else + BLocale::Default()->GetLanguage(&fLanguage); } // copy constructor BDateFormat::BDateFormat(const BDateFormat &other) - : BDateTimeFormat(other) + : fConventions(other.fConventions), + fLanguage(other.fLanguage) { } +/*static*/ const BDateFormat* +BDateFormat::Default() +{ + return BLocaleRoster::Default()->GetDefaultDateFormat(); +} + + // destructor BDateFormat::~BDateFormat() { } // Format -status_t -BDateFormat::Format(bigtime_t value, BString* buffer) const +ssize_t +BDateFormat::Format(char* string, size_t maxSize, time_t time, + BDateFormatStyle style) const { - return B_ERROR; + BAutolock lock(fLock); + if (!lock.IsLocked()) + return B_ERROR; + + BString format; + fConventions.GetDateFormat(style, format); + ObjectDeleter dateFormatter(_CreateDateFormatter(format)); + if (dateFormatter.Get() == NULL) + return B_NO_MEMORY; + + UnicodeString icuString; + dateFormatter->format((UDate)time * 1000, icuString); + + CheckedArrayByteSink stringConverter(string, maxSize); + icuString.toUTF8(stringConverter); + + if (stringConverter.Overflowed()) + return B_BAD_VALUE; + + return stringConverter.NumberOfBytesWritten(); } + + +status_t +BDateFormat::Format(BString *string, time_t time, BDateFormatStyle style, + const BTimeZone* timeZone) const +{ + BAutolock lock(fLock); + if (!lock.IsLocked()) + return B_ERROR; + + BString format; + fConventions.GetDateFormat(style, format); + ObjectDeleter dateFormatter(_CreateDateFormatter(format)); + if (dateFormatter.Get() == NULL) + return B_NO_MEMORY; + + if (timeZone != NULL) { + ObjectDeleter icuTimeZone( + TimeZone::createTimeZone(timeZone->ID().String())); + if (icuTimeZone.Get() == NULL) + return B_NO_MEMORY; + dateFormatter->setTimeZone(*icuTimeZone.Get()); + } + + UnicodeString icuString; + dateFormatter->format((UDate)time * 1000, icuString); + + string->Truncate(0); + BStringByteSink stringConverter(string); + icuString.toUTF8(stringConverter); + + return B_OK; +} + + +status_t +BDateFormat::Format(BString* string, int*& fieldPositions, int& fieldCount, + time_t time, BDateFormatStyle style) const +{ + BAutolock lock(fLock); + if (!lock.IsLocked()) + return B_ERROR; + + BString format; + fConventions.GetDateFormat(style, format); + ObjectDeleter dateFormatter(_CreateDateFormatter(format)); + if (dateFormatter.Get() == NULL) + return B_NO_MEMORY; + + fieldPositions = NULL; + UErrorCode error = U_ZERO_ERROR; + icu::FieldPositionIterator positionIterator; + UnicodeString icuString; + dateFormatter->format((UDate)time * 1000, icuString, &positionIterator, + error); + + if (error != U_ZERO_ERROR) + return B_BAD_VALUE; + + icu::FieldPosition field; + std::vector fieldPosStorage; + fieldCount = 0; + while (positionIterator.next(field)) { + fieldPosStorage.push_back(field.getBeginIndex()); + fieldPosStorage.push_back(field.getEndIndex()); + fieldCount += 2; + } + + fieldPositions = (int*) malloc(fieldCount * sizeof(int)); + + for (int i = 0 ; i < fieldCount ; i++ ) + fieldPositions[i] = fieldPosStorage[i]; + + string->Truncate(0); + BStringByteSink stringConverter(string); + + icuString.toUTF8(stringConverter); + + return B_OK; +} + + +status_t +BDateFormat::GetFields(BDateElement*& fields, int& fieldCount, + BDateFormatStyle style) const +{ + BAutolock lock(fLock); + if (!lock.IsLocked()) + return B_ERROR; + + BString format; + fConventions.GetDateFormat(style, format); + ObjectDeleter dateFormatter(_CreateDateFormatter(format)); + if (dateFormatter.Get() == NULL) + return B_NO_MEMORY; + + fields = NULL; + UErrorCode error = U_ZERO_ERROR; + icu::FieldPositionIterator positionIterator; + UnicodeString icuString; + time_t now; + dateFormatter->format((UDate)time(&now) * 1000, icuString, + &positionIterator, error); + + if (U_FAILURE(error)) + return B_BAD_VALUE; + + icu::FieldPosition field; + std::vector fieldPosStorage; + fieldCount = 0; + while (positionIterator.next(field)) { + fieldPosStorage.push_back(field.getField()); + fieldCount ++; + } + + fields = (BDateElement*) malloc(fieldCount * sizeof(BDateElement)); + + for (int i = 0 ; i < fieldCount ; i++ ) { + switch (fieldPosStorage[i]) { + case UDAT_YEAR_FIELD: + fields[i] = B_DATE_ELEMENT_YEAR; + break; + case UDAT_MONTH_FIELD: + fields[i] = B_DATE_ELEMENT_MONTH; + break; + case UDAT_DATE_FIELD: + fields[i] = B_DATE_ELEMENT_DAY; + break; + default: + fields[i] = B_DATE_ELEMENT_INVALID; + break; + } + } + + return B_OK; +} + + +status_t +BDateFormat::GetStartOfWeek(BWeekday* startOfWeek) const +{ + if (startOfWeek == NULL) + return B_BAD_VALUE; + + BAutolock lock(fLock); + if (!lock.IsLocked()) + return B_ERROR; + + UErrorCode err = U_ZERO_ERROR; + ObjectDeleter calendar = Calendar::createInstance( + *BFormattingConventions::Private(&fConventions).ICULocale(), err); + + if (U_FAILURE(err)) + return B_ERROR; + + UCalendarDaysOfWeek icuWeekStart = calendar->getFirstDayOfWeek(err); + if (U_FAILURE(err)) + return B_ERROR; + + switch (icuWeekStart) { + case UCAL_SUNDAY: + *startOfWeek = B_WEEKDAY_SUNDAY; + break; + case UCAL_MONDAY: + *startOfWeek = B_WEEKDAY_MONDAY; + break; + case UCAL_TUESDAY: + *startOfWeek = B_WEEKDAY_TUESDAY; + break; + case UCAL_WEDNESDAY: + *startOfWeek = B_WEEKDAY_WEDNESDAY; + break; + case UCAL_THURSDAY: + *startOfWeek = B_WEEKDAY_THURSDAY; + break; + case UCAL_FRIDAY: + *startOfWeek = B_WEEKDAY_FRIDAY; + break; + case UCAL_SATURDAY: + *startOfWeek = B_WEEKDAY_SATURDAY; + break; + default: + return B_ERROR; + } + + return B_OK; +} + + +DateFormat* +BDateFormat::_CreateDateFormatter(const BString& format) const +{ + Locale* icuLocale + = fConventions.UseStringsFromPreferredLanguage() + ? BLanguage::Private(&fLanguage).ICULocale() + : BFormattingConventions::Private(&fConventions).ICULocale(); + + icu::DateFormat* dateFormatter + = icu::DateFormat::createDateInstance(DateFormat::kShort, *icuLocale); + if (dateFormatter == NULL) + return NULL; + + SimpleDateFormat* dateFormatterImpl + = static_cast(dateFormatter); + + UnicodeString pattern(format.String()); + dateFormatterImpl->applyPattern(pattern); + + return dateFormatter; +} + + diff --git a/src/kits/locale/Locale.cpp b/src/kits/locale/Locale.cpp index ed2b95ec64..061924aa67 100644 --- a/src/kits/locale/Locale.cpp +++ b/src/kits/locale/Locale.cpp @@ -188,220 +188,6 @@ BLocale::SetLanguage(const BLanguage& newLanguage) // #pragma mark - Date -ssize_t -BLocale::FormatDate(char* string, size_t maxSize, time_t time, - BDateFormatStyle style) const -{ - BAutolock lock(fLock); - if (!lock.IsLocked()) - return B_ERROR; - - BString format; - fConventions.GetDateFormat(style, format); - ObjectDeleter dateFormatter(_CreateDateFormatter(format)); - if (dateFormatter.Get() == NULL) - return B_NO_MEMORY; - - UnicodeString icuString; - dateFormatter->format((UDate)time * 1000, icuString); - - CheckedArrayByteSink stringConverter(string, maxSize); - icuString.toUTF8(stringConverter); - - if (stringConverter.Overflowed()) - return B_BAD_VALUE; - - return stringConverter.NumberOfBytesWritten(); -} - - -status_t -BLocale::FormatDate(BString *string, time_t time, BDateFormatStyle style, - const BTimeZone* timeZone) const -{ - BAutolock lock(fLock); - if (!lock.IsLocked()) - return B_ERROR; - - BString format; - fConventions.GetDateFormat(style, format); - ObjectDeleter dateFormatter(_CreateDateFormatter(format)); - if (dateFormatter.Get() == NULL) - return B_NO_MEMORY; - - if (timeZone != NULL) { - ObjectDeleter icuTimeZone( - TimeZone::createTimeZone(timeZone->ID().String())); - if (icuTimeZone.Get() == NULL) - return B_NO_MEMORY; - dateFormatter->setTimeZone(*icuTimeZone.Get()); - } - - UnicodeString icuString; - dateFormatter->format((UDate)time * 1000, icuString); - - string->Truncate(0); - BStringByteSink stringConverter(string); - icuString.toUTF8(stringConverter); - - return B_OK; -} - - -status_t -BLocale::FormatDate(BString* string, int*& fieldPositions, int& fieldCount, - time_t time, BDateFormatStyle style) const -{ - BAutolock lock(fLock); - if (!lock.IsLocked()) - return B_ERROR; - - BString format; - fConventions.GetDateFormat(style, format); - ObjectDeleter dateFormatter(_CreateDateFormatter(format)); - if (dateFormatter.Get() == NULL) - return B_NO_MEMORY; - - fieldPositions = NULL; - UErrorCode error = U_ZERO_ERROR; - icu::FieldPositionIterator positionIterator; - UnicodeString icuString; - dateFormatter->format((UDate)time * 1000, icuString, &positionIterator, - error); - - if (error != U_ZERO_ERROR) - return B_BAD_VALUE; - - icu::FieldPosition field; - std::vector fieldPosStorage; - fieldCount = 0; - while (positionIterator.next(field)) { - fieldPosStorage.push_back(field.getBeginIndex()); - fieldPosStorage.push_back(field.getEndIndex()); - fieldCount += 2; - } - - fieldPositions = (int*) malloc(fieldCount * sizeof(int)); - - for (int i = 0 ; i < fieldCount ; i++ ) - fieldPositions[i] = fieldPosStorage[i]; - - string->Truncate(0); - BStringByteSink stringConverter(string); - - icuString.toUTF8(stringConverter); - - return B_OK; -} - - -status_t -BLocale::GetDateFields(BDateElement*& fields, int& fieldCount, - BDateFormatStyle style) const -{ - BAutolock lock(fLock); - if (!lock.IsLocked()) - return B_ERROR; - - BString format; - fConventions.GetDateFormat(style, format); - ObjectDeleter dateFormatter(_CreateDateFormatter(format)); - if (dateFormatter.Get() == NULL) - return B_NO_MEMORY; - - fields = NULL; - UErrorCode error = U_ZERO_ERROR; - icu::FieldPositionIterator positionIterator; - UnicodeString icuString; - time_t now; - dateFormatter->format((UDate)time(&now) * 1000, icuString, - &positionIterator, error); - - if (U_FAILURE(error)) - return B_BAD_VALUE; - - icu::FieldPosition field; - std::vector fieldPosStorage; - fieldCount = 0; - while (positionIterator.next(field)) { - fieldPosStorage.push_back(field.getField()); - fieldCount ++; - } - - fields = (BDateElement*) malloc(fieldCount * sizeof(BDateElement)); - - for (int i = 0 ; i < fieldCount ; i++ ) { - switch (fieldPosStorage[i]) { - case UDAT_YEAR_FIELD: - fields[i] = B_DATE_ELEMENT_YEAR; - break; - case UDAT_MONTH_FIELD: - fields[i] = B_DATE_ELEMENT_MONTH; - break; - case UDAT_DATE_FIELD: - fields[i] = B_DATE_ELEMENT_DAY; - break; - default: - fields[i] = B_DATE_ELEMENT_INVALID; - break; - } - } - - return B_OK; -} - - -status_t -BLocale::GetStartOfWeek(BWeekday* startOfWeek) const -{ - if (startOfWeek == NULL) - return B_BAD_VALUE; - - BAutolock lock(fLock); - if (!lock.IsLocked()) - return B_ERROR; - - UErrorCode err = U_ZERO_ERROR; - ObjectDeleter calendar = Calendar::createInstance( - *BFormattingConventions::Private(&fConventions).ICULocale(), err); - - if (U_FAILURE(err)) - return B_ERROR; - - UCalendarDaysOfWeek icuWeekStart = calendar->getFirstDayOfWeek(err); - if (U_FAILURE(err)) - return B_ERROR; - - switch (icuWeekStart) { - case UCAL_SUNDAY: - *startOfWeek = B_WEEKDAY_SUNDAY; - break; - case UCAL_MONDAY: - *startOfWeek = B_WEEKDAY_MONDAY; - break; - case UCAL_TUESDAY: - *startOfWeek = B_WEEKDAY_TUESDAY; - break; - case UCAL_WEDNESDAY: - *startOfWeek = B_WEEKDAY_WEDNESDAY; - break; - case UCAL_THURSDAY: - *startOfWeek = B_WEEKDAY_THURSDAY; - break; - case UCAL_FRIDAY: - *startOfWeek = B_WEEKDAY_FRIDAY; - break; - case UCAL_SATURDAY: - *startOfWeek = B_WEEKDAY_SATURDAY; - break; - default: - return B_ERROR; - } - - return B_OK; -} - - ssize_t BLocale::FormatDateTime(char* target, size_t maxSize, time_t time, BDateFormatStyle dateStyle, BTimeFormatStyle timeStyle) const @@ -847,8 +633,8 @@ BLocale::_CreateDateFormatter(const BString& format) const ? BLanguage::Private(&fLanguage).ICULocale() : BFormattingConventions::Private(&fConventions).ICULocale(); - DateFormat* dateFormatter - = DateFormat::createDateInstance(DateFormat::kShort, *icuLocale); + icu::DateFormat* dateFormatter + = icu::DateFormat::createDateInstance(DateFormat::kShort, *icuLocale); if (dateFormatter == NULL) return NULL; @@ -870,8 +656,8 @@ BLocale::_CreateTimeFormatter(const BString& format) const ? BLanguage::Private(&fLanguage).ICULocale() : BFormattingConventions::Private(&fConventions).ICULocale(); - DateFormat* timeFormatter - = DateFormat::createTimeInstance(DateFormat::kShort, *icuLocale); + icu::DateFormat* timeFormatter + = icu::DateFormat::createTimeInstance(DateFormat::kShort, *icuLocale); if (timeFormatter == NULL) return NULL; diff --git a/src/kits/locale/LocaleRoster.cpp b/src/kits/locale/LocaleRoster.cpp index 115b3c8bff..a86e0a0335 100644 --- a/src/kits/locale/LocaleRoster.cpp +++ b/src/kits/locale/LocaleRoster.cpp @@ -174,6 +174,14 @@ BLocaleRoster::GetDefaultLocale() const return &fData->fDefaultLocale; } + +const BDateFormat* +BLocaleRoster::GetDefaultDateFormat() const +{ + return &fData->fDefaultDateFormat; +} + + status_t BLocaleRoster::GetLanguage(const char* languageCode, BLanguage** _language) const diff --git a/src/kits/locale/LocaleRosterData.cpp b/src/kits/locale/LocaleRosterData.cpp index c6f5300f2c..7aa72e2a4e 100644 --- a/src/kits/locale/LocaleRosterData.cpp +++ b/src/kits/locale/LocaleRosterData.cpp @@ -126,6 +126,7 @@ LocaleRosterData::LocaleRosterData(const BLanguage& language, : fLock("LocaleRosterData"), fDefaultLocale(&language, &conventions), + fDefaultDateFormat(&language, &conventions), fIsFilesystemTranslationPreferred(false), fAreResourcesLoaded(false) { diff --git a/src/kits/shared/CalendarView.cpp b/src/kits/shared/CalendarView.cpp index fab7f2f8fc..f2cae8f0f2 100644 --- a/src/kits/shared/CalendarView.cpp +++ b/src/kits/shared/CalendarView.cpp @@ -654,7 +654,7 @@ BCalendarView::_InitObject() { fDate = BDate::CurrentDate(B_LOCAL_TIME); - BLocale::Default()->GetStartOfWeek((BWeekday*)&fStartOfWeek); + BDateFormat::Default()->GetStartOfWeek((BWeekday*)&fStartOfWeek); _SetupDayNames(); _SetupDayNumbers(); diff --git a/src/kits/tracker/WidgetAttributeText.cpp b/src/kits/tracker/WidgetAttributeText.cpp index 640c40da0b..5daff1f3ed 100644 --- a/src/kits/tracker/WidgetAttributeText.cpp +++ b/src/kits/tracker/WidgetAttributeText.cpp @@ -45,6 +45,7 @@ All rights reserved. #include #include #include +#include #include #include #include @@ -213,7 +214,7 @@ TruncTimeBase(BString* outString, int64 value, const View* view, float width) } if (resultWidth > width - && BLocale::Default()->FormatDate(&date, timeValue, + && BDateFormat::Default()->Format(&date, timeValue, B_SHORT_DATE_FORMAT) == B_OK) { resultWidth = view->StringWidth(date.String(), date.Length()); } diff --git a/src/preferences/locale/FormatSettingsView.cpp b/src/preferences/locale/FormatSettingsView.cpp index 0dc5f6bd5b..0b58029663 100644 --- a/src/preferences/locale/FormatSettingsView.cpp +++ b/src/preferences/locale/FormatSettingsView.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -360,16 +361,16 @@ FormatSettingsView::_UpdateExamples() time_t timeValue = (time_t)time(NULL); BString result; - BLocale::Default()->FormatDate(&result, timeValue, B_FULL_DATE_FORMAT); + BDateFormat::Default()->Format(&result, timeValue, B_FULL_DATE_FORMAT); fFullDateExampleView->SetText(result); - BLocale::Default()->FormatDate(&result, timeValue, B_LONG_DATE_FORMAT); + BDateFormat::Default()->Format(&result, timeValue, B_LONG_DATE_FORMAT); fLongDateExampleView->SetText(result); - BLocale::Default()->FormatDate(&result, timeValue, B_MEDIUM_DATE_FORMAT); + BDateFormat::Default()->Format(&result, timeValue, B_MEDIUM_DATE_FORMAT); fMediumDateExampleView->SetText(result); - BLocale::Default()->FormatDate(&result, timeValue, B_SHORT_DATE_FORMAT); + BDateFormat::Default()->Format(&result, timeValue, B_SHORT_DATE_FORMAT); fShortDateExampleView->SetText(result); BLocale::Default()->FormatTime(&result, timeValue, B_FULL_TIME_FORMAT); diff --git a/src/preferences/time/DateTimeEdit.cpp b/src/preferences/time/DateTimeEdit.cpp index 1a04135fd0..eb2dcc941f 100644 --- a/src/preferences/time/DateTimeEdit.cpp +++ b/src/preferences/time/DateTimeEdit.cpp @@ -16,6 +16,7 @@ #include +#include #include #include #include @@ -622,14 +623,14 @@ TDateEdit::_UpdateFields() free(fFieldPositions); fFieldPositions = NULL; } - BLocale::Default()->FormatDate(&fText, fFieldPositions, fFieldPosCount, + BDateFormat::Default()->Format(&fText, fFieldPositions, fFieldPosCount, time, B_SHORT_DATE_FORMAT); if (fFields != NULL) { free(fFields); fFields = NULL; } - BLocale::Default()->GetDateFields(fFields, fFieldCount, + BDateFormat::Default()->GetFields(fFields, fFieldCount, B_SHORT_DATE_FORMAT); } diff --git a/src/preferences/time/TimeZoneListView.cpp b/src/preferences/time/TimeZoneListView.cpp index 84598c6993..61ca51cc16 100644 --- a/src/preferences/time/TimeZoneListView.cpp +++ b/src/preferences/time/TimeZoneListView.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -50,7 +51,7 @@ TimeZoneListView::GetToolTipAt(BPoint point, BToolTip** _tip) &item->TimeZone()); BString dateInTimeZone; - BLocale::Default()->FormatDate(&dateInTimeZone, now, B_SHORT_DATE_FORMAT, + BDateFormat::Default()->Format(&dateInTimeZone, now, B_SHORT_DATE_FORMAT, &item->TimeZone()); BString toolTip = item->Text();