diff options
author | Eike Rathke <erack@redhat.com> | 2021-07-03 11:46:49 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-07-04 02:28:48 +0200 |
commit | 2cc8ec691cc37b07e4f134bf379164f375b8a481 (patch) | |
tree | 24ccdc458a0e2cb4faeec3958024060c71aa1b67 /vcl/source/control/field2.cxx | |
parent | 79d31d08146afa0861ceb1705262411449e71ec7 (diff) |
Resolves: tdf#125035 Use number formatter for long date in DateFormatter fields
Change-Id: Ib0cd55d9ad4e3abb4839d70c0086063a3f1a90f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118344
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'vcl/source/control/field2.cxx')
-rw-r--r-- | vcl/source/control/field2.cxx | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx index b66e226262ff..603415672f38 100644 --- a/vcl/source/control/field2.cxx +++ b/vcl/source/control/field2.cxx @@ -40,6 +40,7 @@ #include <unotools/localedatawrapper.hxx> #include <unotools/calendarwrapper.hxx> #include <unotools/charclass.hxx> +#include <svl/zforlist.hxx> using namespace ::com::sun::star; using namespace ::comphelper; @@ -1387,7 +1388,8 @@ namespace } OUString DateFormatter::FormatDate(const Date& rDate, ExtDateFieldFormat eExtFormat, - const LocaleDataWrapper& rLocaleData, CalendarWrapper& rCalendarWrapper) + const LocaleDataWrapper& rLocaleData, CalendarWrapper& rCalendarWrapper, + const Formatter::StaticFormatter* pStaticFormatter) { bool bShowCentury = false; switch (eExtFormat) @@ -1437,7 +1439,22 @@ OUString DateFormatter::FormatDate(const Date& rDate, ExtDateFieldFormat eExtFor { case ExtDateFieldFormat::SystemLong: { - return rLocaleData.getLongDate( rDate, rCalendarWrapper, !bShowCentury ); + /* TODO: adapt all callers to pass a StaticFormatter. */ + if (!pStaticFormatter) + return rLocaleData.getLongDate( rDate, rCalendarWrapper, !bShowCentury ); + else + { + SvNumberFormatter* pFormatter = *pStaticFormatter; + const LanguageTag aFormatterLang( pFormatter->GetLanguageTag()); + const sal_uInt32 nIndex = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_LONG, + rLocaleData.getLanguageTag().getLanguageType(false)); + OUString aStr; + const Color* pCol; + pFormatter->GetOutputString( rDate - pFormatter->GetNullDate(), nIndex, aStr, &pCol); + // Reset to what other uses may expect. + pFormatter->ChangeIntl( aFormatterLang.getLanguageType(false)); + return aStr; + } } case ExtDateFieldFormat::ShortDDMMYY: case ExtDateFieldFormat::ShortDDMMYYYY: @@ -1482,7 +1499,8 @@ OUString DateFormatter::FormatDate(const Date& rDate, ExtDateFieldFormat eExtFor OUString DateFormatter::ImplGetDateAsText( const Date& rDate ) const { - return DateFormatter::FormatDate(rDate, GetExtDateFormat(), ImplGetLocaleDataWrapper(), GetCalendarWrapper()); + return DateFormatter::FormatDate(rDate, GetExtDateFormat(), ImplGetLocaleDataWrapper(), + GetCalendarWrapper(), &maStaticFormatter); } static void ImplDateIncrementDay( Date& rDate, bool bUp ) |