diff --git a/headers/os/locale/DateFormat.h b/headers/os/locale/DateFormat.h index ec11d7fead..d0b1325ebd 100644 --- a/headers/os/locale/DateFormat.h +++ b/headers/os/locale/DateFormat.h @@ -37,6 +37,14 @@ public: static const BDateFormat* Default(); + void SetLanguage(const BLanguage& newLanguage); + void SetFormattingConventions( + const BFormattingConventions& conventions); + status_t GetDateFormat(BDateFormatStyle style, + BString& outFormat) const; + void SetDateFormat(BDateFormatStyle style, + const BString& format); + // formatting ssize_t Format(char* string, const size_t maxSize, diff --git a/src/kits/locale/DateFormat.cpp b/src/kits/locale/DateFormat.cpp index 8521a42e9b..bf1542f263 100644 --- a/src/kits/locale/DateFormat.cpp +++ b/src/kits/locale/DateFormat.cpp @@ -4,6 +4,7 @@ * * Authors: * Oliver Tappe + * Adrien Desutugues */ #include @@ -58,6 +59,44 @@ BDateFormat::~BDateFormat() } +void +BDateFormat::SetFormattingConventions(const BFormattingConventions& conventions) +{ + BAutolock lock(fLock); + if (!lock.IsLocked()) + return; + + fConventions = conventions; +} + + +void +BDateFormat::SetLanguage(const BLanguage& newLanguage) +{ + BAutolock lock(fLock); + if (!lock.IsLocked()) + return; + + fLanguage = newLanguage; +} + + +status_t +BDateFormat::GetDateFormat(BDateFormatStyle style, + BString& outFormat) const +{ + return fConventions.GetDateFormat(style, outFormat); +} + + +void +BDateFormat::SetDateFormat(BDateFormatStyle style, + const BString& format) +{ + fConventions.SetExplicitDateFormat(style, format); +} + + ssize_t BDateFormat::Format(char* string, const size_t maxSize, const time_t time, const BDateFormatStyle style) const diff --git a/src/kits/locale/LocaleRosterData.cpp b/src/kits/locale/LocaleRosterData.cpp index 7aa72e2a4e..a632540818 100644 --- a/src/kits/locale/LocaleRosterData.cpp +++ b/src/kits/locale/LocaleRosterData.cpp @@ -467,6 +467,7 @@ LocaleRosterData::_LoadLocaleSettings() if (status == B_OK) { BFormattingConventions conventions(&settings); fDefaultLocale.SetFormattingConventions(conventions); + fDefaultDateFormat.SetFormattingConventions(conventions); _SetPreferredLanguages(&settings); @@ -485,8 +486,10 @@ LocaleRosterData::_LoadLocaleSettings() fPreferredLanguages.AddString(kLanguageField, "en"); BLanguage defaultLanguage("en_US"); fDefaultLocale.SetLanguage(defaultLanguage); + fDefaultDateFormat.SetLanguage(defaultLanguage); BFormattingConventions conventions("en_US"); fDefaultLocale.SetFormattingConventions(conventions); + fDefaultDateFormat.SetFormattingConventions(conventions); return status; } @@ -582,6 +585,7 @@ LocaleRosterData::_SetDefaultFormattingConventions( const BFormattingConventions& newFormattingConventions) { fDefaultLocale.SetFormattingConventions(newFormattingConventions); + fDefaultDateFormat.SetFormattingConventions(newFormattingConventions); UErrorCode icuError = U_ZERO_ERROR; Locale icuLocale = Locale::createCanonical(newFormattingConventions.ID()); @@ -618,6 +622,7 @@ LocaleRosterData::_SetPreferredLanguages(const BMessage* languages) && languages->FindString(kLanguageField, &langName) == B_OK) { fDefaultLocale.SetCollator(BCollator(langName.String())); fDefaultLocale.SetLanguage(BLanguage(langName.String())); + fDefaultDateFormat.SetLanguage(BLanguage(langName.String())); fPreferredLanguages.RemoveName(kLanguageField); for (int i = 0; languages->FindString(kLanguageField, i, &langName)