diff options
author | Mike FABIAN <mike.fabian@basyskom.de> | 2010-08-17 16:28:48 +0200 |
---|---|---|
committer | Mike FABIAN <mike.fabian@basyskom.de> | 2010-08-26 13:25:21 +0200 |
commit | df6be0c5b7ec373612026d09a7119f113f58862d (patch) | |
tree | cf7bdefdc9d7cd00cd76a95586bc8d3c6422e9f9 | |
parent | bb9611fff49d519be6832b53f68f999711241fa8 (diff) |
Fixes: NB#160042 - DuiLocale does not respect 24h time format preference
RevBy: Holger Schröder
Details:
- add new gconf key "/meegotouch/i18n/lc_timeformat24h"
This key can have 3 values:
- 1) "12" force 12 hour mode when formatting times.
- 2) "24" force 24 hour mode when formatting times.
- 3) anything which is *neither* "12" *nor* "24" (e.g. "")
makes formatting times use the default for the locale.
- fix %r and %R for Japanese.
- add stuff to the unit tests to test the new features.
-rw-r--r-- | src/corelib/i18n/mlocale.cpp | 275 | ||||
-rw-r--r-- | src/corelib/i18n/mlocale.h | 29 | ||||
-rw-r--r-- | src/corelib/i18n/mlocale_p.h | 22 | ||||
-rw-r--r-- | tests/ft_locales/ft_locales.cpp | 82 | ||||
-rw-r--r-- | tests/ut_mcalendar/ut_mcalendar.cpp | 500 | ||||
-rw-r--r-- | tests/ut_mcalendar/ut_mcalendar.h | 15 |
6 files changed, 838 insertions, 85 deletions
diff --git a/src/corelib/i18n/mlocale.cpp b/src/corelib/i18n/mlocale.cpp index ad01ddfe..fcd64947 100644 --- a/src/corelib/i18n/mlocale.cpp +++ b/src/corelib/i18n/mlocale.cpp @@ -58,6 +58,7 @@ namespace const QString SettingsLanguage("/meegotouch/i18n/language"); const QString SettingsLcTime("/meegotouch/i18n/lc_time"); + const QString SettingsLcTimeFormat24h("/meegotouch/i18n/lc_timeformat24h"); const QString SettingsLcCollate("/meegotouch/i18n/lc_collate"); const QString SettingsLcNumeric("/meegotouch/i18n/lc_numeric"); const QString SettingsLcMonetary("/meegotouch/i18n/lc_monetary"); @@ -275,10 +276,186 @@ icu::DateFormatSymbols *MLocalePrivate::createDateFormatSymbols(const icu::Local } #endif +static bool isTwelveHours(const QString &icuFormatQString) +{ + if (icuFormatQString.contains('\'')) { + bool isQuoted = false; + for (int i = 0; i < icuFormatQString.size(); ++i) { + if (icuFormatQString[i] == '\'') + isQuoted = !isQuoted; + if (!isQuoted && icuFormatQString[i] == 'a') + return true; + } + return false; + } + else { + if(icuFormatQString.contains('a')) + return true; + else + return false; + } +} + +#ifdef HAVE_ICU +void MLocalePrivate::dateFormatTo24h(icu::DateFormat *df) const +{ + if (df) { + icu::UnicodeString icuFormatString; + QString icuFormatQString; + static_cast<SimpleDateFormat *>(df)->toPattern(icuFormatString); + icuFormatQString = MIcuConversions::unicodeStringToQString(icuFormatString); + if (isTwelveHours(icuFormatQString)) { + // remove unquoted 'a' characters and remove space left of 'a' + // and change unquoted h -> H and K -> k + QString tmp; + bool isQuoted = false; + for (int i = 0; i < icuFormatQString.size(); ++i) { + QChar c = icuFormatQString[i]; + if (c == '\'') + isQuoted = !isQuoted; + if (!isQuoted) { + if (c == 'h') + tmp.append("H"); + else if (c == 'K') + tmp.append("k"); + else if (c == 'a') { + if (tmp.endsWith(' ')) { + // remove space before 'a' if character + // after 'a' is space as well: + if (i < icuFormatQString.size() - 1 + && icuFormatQString[i+1] == ' ') + tmp.remove(tmp.size()-1,1); + // remove space before 'a' if 'a' is last + // character in string: + if (i == icuFormatQString.size() - 1) + tmp.remove(tmp.size()-1,1); + } + } + else + tmp.append(c); + } + else { + tmp.append(c); + } + } + icuFormatQString = tmp; + } + icuFormatString = MIcuConversions::qStringToUnicodeString(icuFormatQString); + static_cast<SimpleDateFormat *>(df)->applyPattern(icuFormatString); + } +} +#endif + +#ifdef HAVE_ICU +void MLocalePrivate::dateFormatTo12h(icu::DateFormat *df) const +{ + if (df) { + icu::UnicodeString icuFormatString; + QString icuFormatQString; + static_cast<SimpleDateFormat *>(df)->toPattern(icuFormatString); + icuFormatQString = MIcuConversions::unicodeStringToQString(icuFormatString); + if (!isTwelveHours(icuFormatQString)) { + // change unquoted H -> h and k -> K + // add 'a' at the right position (maybe adding a space as well) + QString tmp; + bool isQuoted = false; + bool amPmMarkerWritten = false; + QString language = categoryName(MLocale::MLcTime); + bool writeAmPmMarkerBeforeHours = false; + if (language.startsWith("ja") || language.startsWith("zh")) + writeAmPmMarkerBeforeHours = true; + if (writeAmPmMarkerBeforeHours) { + for (int i = 0; i < icuFormatQString.size(); ++i) { + QChar c = icuFormatQString[i]; + if (c == '\'') + isQuoted = !isQuoted; + if (!isQuoted) { + if (c == 'H') { + if (!amPmMarkerWritten) { + tmp.append("a"); + amPmMarkerWritten = true; + } + tmp.append("h"); + } + else if (c == 'k') { + if (!amPmMarkerWritten) { + tmp.append("a"); + amPmMarkerWritten = true; + } + tmp.append("K"); + } + else + tmp.append(c); + } + else { + tmp.append(c); + } + } + icuFormatQString = tmp; + } + else { + for (int i = 0; i < icuFormatQString.size(); ++i) { + QChar c = icuFormatQString[i]; + if (c == '\'') + isQuoted = !isQuoted; + if (!isQuoted) { + if (c == 'H') + tmp.append("h"); + else if (c == 'k') + tmp.append("K"); + else if (c == 'z') { + if (!amPmMarkerWritten) { + if (!tmp.endsWith(' ')) + tmp.append(' '); + tmp.append("a "); + amPmMarkerWritten = true; + } + tmp.append(c); + } + else + tmp.append(c); + } + else { + tmp.append(c); + } + } + if (!amPmMarkerWritten) + tmp.append(" a"); + icuFormatQString = tmp; + } + } + icuFormatString = MIcuConversions::qStringToUnicodeString(icuFormatQString); + static_cast<SimpleDateFormat *>(df)->applyPattern(icuFormatString); + } +} +#endif + +#ifdef HAVE_ICU +QString MLocalePrivate::icuFormatString(MLocale::DateType dateType, + MLocale::TimeType timeType, + MLocale::CalendarType calendarType, + MLocale::TimeFormat24h timeFormat24h) const +{ + icu::DateFormat *df = createDateFormat(dateType, timeType, calendarType, timeFormat24h); + + QString icuFormatQString; + + if (df) + { + icu::UnicodeString icuFormatString; + static_cast<SimpleDateFormat *>(df)->toPattern(icuFormatString); + icuFormatQString = MIcuConversions::unicodeStringToQString(icuFormatString); + delete df; + } + return icuFormatQString; +} +#endif + #ifdef HAVE_ICU icu::DateFormat *MLocalePrivate::createDateFormat(MLocale::DateType dateType, MLocale::TimeType timeType, - MLocale::CalendarType calendarType) const + MLocale::CalendarType calendarType, + MLocale::TimeFormat24h timeFormat24h) const { // Create calLocale which has the time pattern we want to use icu::Locale calLocale = MIcuConversions::createLocale( @@ -301,6 +478,20 @@ icu::DateFormat *MLocalePrivate::createDateFormat(MLocale::DateType dateType, // symbols with the public API static_cast<SimpleDateFormat *>(df)->adoptDateFormatSymbols(dfs); #endif + if (timeType == MLocale::TimeNone) + return df; + switch (timeFormat24h) { + case(MLocale::TwelveHourTimeFormat24h): + MLocalePrivate::dateFormatTo12h(df); + break; + case(MLocale::TwentyFourHourTimeFormat24h): + MLocalePrivate::dateFormatTo24h(df); + break; + case(MLocale::LocaleDefaultTimeFormat24h): + break; + default: + break; + } return df; } #endif @@ -311,6 +502,7 @@ MLocalePrivate::MLocalePrivate() : _valid(true), _calendarType(MLocale::DefaultCalendar), _collation(MLocale::DefaultCollation), + _timeFormat24h(MLocale::LocaleDefaultTimeFormat24h), _phoneNumberGrouping( MLocale::DefaultPhoneNumberGrouping ), #ifdef HAVE_ICU _numberFormat(0), @@ -319,6 +511,7 @@ MLocalePrivate::MLocalePrivate() #ifdef HAVE_GCONF currentLanguageItem(SettingsLanguage), currentLcTimeItem(SettingsLcTime), + currentLcTimeFormat24hItem(SettingsLcTimeFormat24h), currentLcCollateItem(SettingsLcCollate), currentLcNumericItem(SettingsLcNumeric), currentLcMonetaryItem(SettingsLcMonetary), @@ -346,6 +539,7 @@ MLocalePrivate::MLocalePrivate(const MLocalePrivate &other) _validCountryCodes( other._validCountryCodes ), _calendarType(other._calendarType), _collation(other._collation), + _timeFormat24h(other._timeFormat24h), _phoneNumberGrouping( other._phoneNumberGrouping ), #ifdef HAVE_ICU _numberFormat(0), @@ -357,6 +551,7 @@ MLocalePrivate::MLocalePrivate(const MLocalePrivate &other) #ifdef HAVE_GCONF currentLanguageItem(SettingsLanguage), currentLcTimeItem(SettingsLcTime), + currentLcTimeFormat24hItem(SettingsLcTimeFormat24h), currentLcCollateItem(SettingsLcCollate), currentLcNumericItem(SettingsLcNumeric), currentLcMonetaryItem(SettingsLcMonetary), @@ -396,6 +591,7 @@ MLocalePrivate &MLocalePrivate::operator=(const MLocalePrivate &other) _nameLocale = other._nameLocale; _calendarType = other._calendarType; _collation = other._collation; + _timeFormat24h = other._timeFormat24h; _messageTranslations = other._messageTranslations; _timeTranslations = other._timeTranslations; _trTranslations = other._trTranslations; @@ -930,6 +1126,7 @@ MLocale::createSystemMLocale() #ifdef HAVE_GCONF MGConfItem languageItem(SettingsLanguage); MGConfItem lcTimeItem(SettingsLcTime); + MGConfItem lcTimeFormat24hItem(SettingsLcTimeFormat24h); MGConfItem lcCollateItem(SettingsLcCollate); MGConfItem lcNumericItem(SettingsLcNumeric); MGConfItem lcMonetaryItem(SettingsLcMonetary); @@ -937,6 +1134,7 @@ MLocale::createSystemMLocale() QString language = languageItem.value().toString(); QString lcTime = lcTimeItem.value().toString(); + QString lcTimeFormat24h = lcTimeFormat24hItem.value().toString(); QString lcCollate = lcCollateItem.value().toString(); QString lcNumeric = lcNumericItem.value().toString(); QString lcMonetary = lcMonetaryItem.value().toString(); @@ -959,6 +1157,12 @@ MLocale::createSystemMLocale() if (!lcTime.isEmpty()) systemLocale->setCategoryLocale(MLocale::MLcTime, lcTime); + if (lcTimeFormat24h == "24") + systemLocale->setTimeFormat24h(MLocale::TwentyFourHourTimeFormat24h); + else if (lcTimeFormat24h == "12") + systemLocale->setTimeFormat24h(MLocale::TwelveHourTimeFormat24h); + else + systemLocale->setTimeFormat24h(MLocale::LocaleDefaultTimeFormat24h); if (!lcCollate.isEmpty()) systemLocale->setCategoryLocale(MLocale::MLcCollate, lcCollate); if (!lcNumeric.isEmpty()) @@ -994,6 +1198,8 @@ MLocale::connectSettings() this, SLOT(refreshSettings())); QObject::connect(&d->currentLcTimeItem, SIGNAL(valueChanged()), this, SLOT(refreshSettings())); + QObject::connect(&d->currentLcTimeFormat24hItem, SIGNAL(valueChanged()), + this, SLOT(refreshSettings())); QObject::connect(&d->currentLcCollateItem, SIGNAL(valueChanged()), this, SLOT(refreshSettings())); QObject::connect(&d->currentLcNumericItem, SIGNAL(valueChanged()), @@ -1015,6 +1221,8 @@ MLocale::disconnectSettings() this, SLOT(refreshSettings())); QObject::disconnect(&d->currentLcTimeItem, SIGNAL(valueChanged()), this, SLOT(refreshSettings())); + QObject::disconnect(&d->currentLcTimeFormat24hItem, SIGNAL(valueChanged()), + this, SLOT(refreshSettings())); QObject::disconnect(&d->currentLcCollateItem, SIGNAL(valueChanged()), this, SLOT(refreshSettings())); QObject::disconnect(&d->currentLcNumericItem, SIGNAL(valueChanged()), @@ -1231,13 +1439,24 @@ void MLocale::setCalendarType(CalendarType calendarType) d->_calendarType = calendarType; } - MLocale::CalendarType MLocale::calendarType() const { Q_D(const MLocale); return d->_calendarType; } +void MLocale::setTimeFormat24h(TimeFormat24h timeFormat24h) +{ + Q_D(MLocale); + d->_timeFormat24h = timeFormat24h; +} + +MLocale::TimeFormat24h MLocale::timeFormat24h() const +{ + Q_D(const MLocale); + return d->_timeFormat24h; +} + #ifdef HAVE_ICU MCollator MLocale::collator() const { @@ -1480,10 +1699,11 @@ QString MLocale::formatDateTime(const MCalendar &mcalendar, icu::UnicodeString resString; icu::Calendar *cal = mcalendar.d_ptr->_calendar; - icu::DateFormat *df = d->createDateFormat(datetype, timetype, mcalendar.type()); + icu::DateFormat *df = d->createDateFormat(datetype, timetype, + mcalendar.type(), + d->_timeFormat24h); df->format(*cal, resString, pos); delete df; - return MIcuConversions::unicodeStringToQString(resString); } #endif @@ -1724,12 +1944,9 @@ QString MLocale::formatDateTime(const MCalendar &mCalendar, case 'r': { // 12 hour clock with am/pm QString timeShortFormat - = icuFormatString(MLocale::DateNone, MLocale::TimeShort, - MLocale::GregorianCalendar); - timeShortFormat.replace(QChar('k'), QChar('K'), Qt::CaseSensitive); - timeShortFormat.replace(QChar('H'), QChar('h'), Qt::CaseSensitive); - if (!timeShortFormat.contains('a', Qt::CaseSensitive)) - timeShortFormat.append(QLatin1String(" a")); + = d->icuFormatString(MLocale::DateNone, MLocale::TimeShort, + MLocale::GregorianCalendar, + MLocale::TwelveHourTimeFormat24h); icuFormat.append(timeShortFormat); break; } @@ -1737,11 +1954,9 @@ QString MLocale::formatDateTime(const MCalendar &mCalendar, case 'R': { // 24-hour clock time, in the format "%H:%M" QString timeShortFormat - = icuFormatString(MLocale::DateNone, MLocale::TimeShort, - MLocale::GregorianCalendar); - timeShortFormat.replace(QRegExp(" *a"), QLatin1String("")); - timeShortFormat.replace(QChar('K'), QChar('k'), Qt::CaseSensitive); - timeShortFormat.replace(QChar('h'), QChar('H'), Qt::CaseSensitive); + = d->icuFormatString(MLocale::DateNone, MLocale::TimeShort, + MLocale::GregorianCalendar, + MLocale::TwentyFourHourTimeFormat24h); icuFormat.append(timeShortFormat); break; } @@ -1917,18 +2132,8 @@ QString MLocale::icuFormatString( DateType dateType, CalendarType calendarType) const { Q_D(const MLocale); - icu::DateFormat *df = d->createDateFormat(dateType, timeType, calendarType); - - QString icuFormatQString; - - if (df) - { - icu::UnicodeString icuFormatString; - static_cast<SimpleDateFormat *>(df)->toPattern(icuFormatString); - icuFormatQString = MIcuConversions::unicodeStringToQString(icuFormatString); - delete df; - } - return icuFormatQString; + return d->icuFormatString(dateType, timeType, calendarType, + d->_timeFormat24h); } #endif @@ -1943,7 +2148,9 @@ QDateTime MLocale::parseDateTime(const QString &dateTime, DateType dateType, MCalendar mcalendar(calendarType); UnicodeString text = MIcuConversions::qStringToUnicodeString(dateTime); - icu::DateFormat *df = d->createDateFormat(dateType, timeType, mcalendar.type()); + icu::DateFormat *df = d->createDateFormat(dateType, timeType, + mcalendar.type(), + d->_timeFormat24h); icu::ParsePosition pos(0); UDate parsedDate = df->parse(text, pos); delete df; @@ -2338,6 +2545,7 @@ void MLocale::refreshSettings() bool settingsHaveReallyChanged = false; QString localeName = d->currentLanguageItem.value().toString(); QString lcTime = d->currentLcTimeItem.value().toString(); + QString lcTimeFormat24h = d->currentLcTimeFormat24hItem.value().toString(); QString lcCollate = d->currentLcCollateItem.value().toString(); QString lcNumeric = d->currentLcNumericItem.value().toString(); QString lcMonetary = d->currentLcMonetaryItem.value().toString(); @@ -2355,6 +2563,17 @@ void MLocale::refreshSettings() settingsHaveReallyChanged = true; setCategoryLocale(MLcTime, lcTime); } + MLocale::TimeFormat24h timeFormat24h; + if (lcTimeFormat24h == "24") + timeFormat24h = MLocale::TwentyFourHourTimeFormat24h; + else if (lcTimeFormat24h == "12") + timeFormat24h = MLocale::TwelveHourTimeFormat24h; + else + timeFormat24h = MLocale::LocaleDefaultTimeFormat24h; + if (timeFormat24h != d->_timeFormat24h) { + settingsHaveReallyChanged = true; + d->_timeFormat24h = timeFormat24h; + } if (lcCollate != d->_collationLocale) { settingsHaveReallyChanged = true; setCategoryLocale(MLcCollate, lcCollate); diff --git a/src/corelib/i18n/mlocale.h b/src/corelib/i18n/mlocale.h index f048ef16..2eec708d 100644 --- a/src/corelib/i18n/mlocale.h +++ b/src/corelib/i18n/mlocale.h @@ -144,6 +144,25 @@ public: CopticCalendar, EthiopicCalendar }; + /*! + * \brief Type to select 12 hour clock or 24 hour clock or default + * + * Chooses whether 12 hour clock or 24 hour clock should be forced + * or whether the default for the current locale should be used. + * + * For example, the “en_US” locale uses a 12 hour clock by + * default, i.e. in case of “en_US”, both + * “LocaleDefaultTimeFormat24h“ and “TwelveHourTimeFormat24h” + * will have the effect that a 12 hour clock is used. + * + * “TwentyFourHourTimeFormat24h” and “TwelveHourTimeFormat24h” + * will force the use of a 24 hour clock or 12 hour clock, respectively, + * no matter which one is used by default in this locale. + */ + enum TimeFormat24h {LocaleDefaultTimeFormat24h, + TwelveHourTimeFormat24h, + TwentyFourHourTimeFormat24h}; + enum Weekday {Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }; @@ -342,6 +361,16 @@ public: CalendarType calendarType() const; /*! + * \brief Sets whether 24 hour clock, 12 hour clock or default is used + */ + void setTimeFormat24h(TimeFormat24h timeFormat24h); + + /*! + * \brief Returns whether 24 hour clock, 12 hour clock or default is used + */ + TimeFormat24h timeFormat24h() const; + + /*! * \brief Returns a MCollator which compares QStrings based on language/country/collation rules */ MCollator collator() const; diff --git a/src/corelib/i18n/mlocale_p.h b/src/corelib/i18n/mlocale_p.h index d32583bf..73e73f86 100644 --- a/src/corelib/i18n/mlocale_p.h +++ b/src/corelib/i18n/mlocale_p.h @@ -87,11 +87,29 @@ public: static icu::DateFormatSymbols *createDateFormatSymbols(const icu::Locale &locale); + // converts an ICU date format to 24 hour clock + void dateFormatTo24h(icu::DateFormat *df) const; + // converts an ICU date format to 12 hour clock + void dateFormatTo12h(icu::DateFormat *df) const; + + /*! + * \brief returns ICU date and time format string of the current locale + * \param dateType style of date formatting + * \param timeType style of time formatting + * \param calendarType calendar to use for formatting + * \param timeFormat24h enum to choose 12 hour or 24 hour or default time format + */ + QString icuFormatString(MLocale::DateType dateType, + MLocale::TimeType timeType, + MLocale::CalendarType calendarType, + MLocale::TimeFormat24h timeFormat24h) const; + // creates a dateformat object for datetime formatting/parsing // the caller is responsible for deleting the dateformat object icu::DateFormat *createDateFormat(MLocale::DateType dateType, MLocale::TimeType timeType, - MLocale::CalendarType calendarType) const; + MLocale::CalendarType calendarType, + MLocale::TimeFormat24h timeFormat24h) const; #endif // these return the requested part of a locale string, @@ -125,6 +143,7 @@ public: // the used calendar and collation may be overridden MLocale::CalendarType _calendarType; MLocale::Collation _collation; + MLocale::TimeFormat24h _timeFormat24h; // add currency? MLocale::PhoneNumberGrouping _phoneNumberGrouping; @@ -149,6 +168,7 @@ public: #ifdef HAVE_GCONF MGConfItem currentLanguageItem; MGConfItem currentLcTimeItem; + MGConfItem currentLcTimeFormat24hItem; MGConfItem currentLcCollateItem; MGConfItem currentLcNumericItem; MGConfItem currentLcMonetaryItem; diff --git a/tests/ft_locales/ft_locales.cpp b/tests/ft_locales/ft_locales.cpp index b17fc4c4..c23d5421 100644 --- a/tests/ft_locales/ft_locales.cpp +++ b/tests/ft_locales/ft_locales.cpp @@ -886,6 +886,7 @@ void Ft_Locales::checkAvailableLocales() // sort the list for easier comparision in the output // (i.e. es_419 should be near es, not at the end of the list): qSort(supportedLocaleNames.begin(), supportedLocaleNames.end()); + MCalendar::setSystemTimeZone("GMT+0"); QDateTime dateTime(QDate(2008, 7, 21), QTime(14, 31, 0, 0), Qt::LocalTime); MCalendar gregorianCalendar(MLocale::GregorianCalendar); MCalendar islamicCalendar(MLocale::IslamicCalendar); @@ -909,6 +910,7 @@ void Ft_Locales::checkAvailableLocales() QString ft_localesTestOutput = ""; foreach(QString supportedLocaleName, supportedLocaleNames) { MLocale locale(supportedLocaleName); + locale.setTimeFormat24h(MLocale::LocaleDefaultTimeFormat24h); qSort(sortingTestList.begin(), sortingTestList.end(), locale.collator()); QString newLinePlusSupportedLocaleName('\n' + supportedLocaleName); ft_localesTestOutput @@ -924,34 +926,6 @@ void Ft_Locales::checkAvailableLocales() + locale.formatCurrency(1234.56, "EUR") + newLinePlusSupportedLocaleName + "\tNegative Currency value\t" + locale.formatCurrency(-1234.56, "EUR") - + newLinePlusSupportedLocaleName + "\t%r (locale specific 12 hour “TimeShort”)\t" - + locale.formatDateTime(gregorianCalendar, "%r") - + newLinePlusSupportedLocaleName + "\t%R (locale specific 24 hour “TimeShort”)\t" - + locale.formatDateTime(gregorianCalendar, "%R") - + newLinePlusSupportedLocaleName + "\tDate and time short (Gregorian Calendar)\t" - + locale.formatDateTime(gregorianCalendar, - MLocale::DateShort, MLocale::TimeShort) - + newLinePlusSupportedLocaleName + "\tDate and time medium (Gregorian Calendar)\t" - + locale.formatDateTime(gregorianCalendar, - MLocale::DateMedium, MLocale::TimeMedium) - + newLinePlusSupportedLocaleName + "\tDate and time long (Gregorian Calendar)\t" - + locale.formatDateTime(gregorianCalendar, - MLocale::DateLong, MLocale::TimeLong) - + newLinePlusSupportedLocaleName + "\tDate and time full (Gregorian Calendar)\t" - + locale.formatDateTime(gregorianCalendar, - MLocale::DateFull, MLocale::TimeFull) - + newLinePlusSupportedLocaleName + "\tDate and time short (Islamic Calendar)\t" - + locale.formatDateTime(islamicCalendar, - MLocale::DateShort, MLocale::TimeShort) - + newLinePlusSupportedLocaleName + "\tDate and time medium (Islamic Calendar)\t" - + locale.formatDateTime(islamicCalendar, - MLocale::DateMedium, MLocale::TimeMedium) - + newLinePlusSupportedLocaleName + "\tDate and time long (Islamic Calendar)\t" - + locale.formatDateTime(islamicCalendar, - MLocale::DateLong, MLocale::TimeLong) - + newLinePlusSupportedLocaleName + "\tDate and time full (Islamic Calendar)\t" - + locale.formatDateTime(islamicCalendar, - MLocale::DateFull, MLocale::TimeFull) + newLinePlusSupportedLocaleName + "\tName of month 01 (Gregorian Calendar)\t" + locale.monthName(gregorianCalendar, 1) + newLinePlusSupportedLocaleName + "\tName of month 02 (Gregorian Calendar)\t" @@ -1102,6 +1076,58 @@ void Ft_Locales::checkAvailableLocales() + sortingTestList.join(" ") + newLinePlusSupportedLocaleName + "\tScripts used\t" + locale.localeScripts().join(" ") + + newLinePlusSupportedLocaleName + "\t%r (locale specific 12 hour “TimeShort”)\t" + + locale.formatDateTime(gregorianCalendar, "%r") + + newLinePlusSupportedLocaleName + "\t%R (locale specific 24 hour “TimeShort”)\t" + + locale.formatDateTime(gregorianCalendar, "%R") + + newLinePlusSupportedLocaleName + "\tDate and time short (Gregorian Calendar)\t" + + locale.icuFormatString(MLocale::DateShort, MLocale::TimeShort, + MLocale::GregorianCalendar) + + " -> " + + locale.formatDateTime(gregorianCalendar, + MLocale::DateShort, MLocale::TimeShort) + + newLinePlusSupportedLocaleName + "\tDate and time medium (Gregorian Calendar)\t" + + locale.icuFormatString(MLocale::DateMedium, MLocale::TimeMedium, + MLocale::GregorianCalendar) + + " -> " + + locale.formatDateTime(gregorianCalendar, + MLocale::DateMedium, MLocale::TimeMedium) + + newLinePlusSupportedLocaleName + "\tDate and time long (Gregorian Calendar)\t" + + locale.icuFormatString(MLocale::DateLong, MLocale::TimeLong, + MLocale::GregorianCalendar) + + " -> " + + locale.formatDateTime(gregorianCalendar, + MLocale::DateLong, MLocale::TimeLong) + + newLinePlusSupportedLocaleName + "\tDate and time full (Gregorian Calendar)\t" + + locale.icuFormatString(MLocale::DateFull, MLocale::TimeFull, + MLocale::GregorianCalendar) + + " -> " + + locale.formatDateTime(gregorianCalendar, + MLocale::DateFull, MLocale::TimeFull) + + newLinePlusSupportedLocaleName + "\tDate and time short (Islamic Calendar)\t" + + locale.icuFormatString(MLocale::DateShort, MLocale::TimeShort, + MLocale::IslamicCalendar) + + " -> " + + locale.formatDateTime(islamicCalendar, + MLocale::DateShort, MLocale::TimeShort) + + newLinePlusSupportedLocaleName + "\tDate and time medium (Islamic Calendar)\t" + + locale.icuFormatString(MLocale::DateMedium, MLocale::TimeMedium, + MLocale::IslamicCalendar) + + " -> " + + locale.formatDateTime(islamicCalendar, + MLocale::DateMedium, MLocale::TimeMedium) + + newLinePlusSupportedLocaleName + "\tDate and time long (Islamic Calendar)\t" + + locale.icuFormatString(MLocale::DateLong, MLocale::TimeLong, + MLocale::IslamicCalendar) + + " -> " + + locale.formatDateTime(islamicCalendar, + MLocale::DateLong, MLocale::TimeLong) + + newLinePlusSupportedLocaleName + "\tDate and time full (Islamic Calendar)\t" + + locale.icuFormatString(MLocale::DateFull, MLocale::TimeFull, + MLocale::IslamicCalendar) + + " -> " + + locale.formatDateTime(islamicCalendar, + MLocale::DateFull, MLocale::TimeFull) + '\n'; } QString ft_localesTestOutputFileName = diff --git a/tests/ut_mcalendar/ut_mcalendar.cpp b/tests/ut_mcalendar/ut_mcalendar.cpp index a6954e60..53cecb0c 100644 --- a/tests/ut_mcalendar/ut_mcalendar.cpp +++ b/tests/ut_mcalendar/ut_mcalendar.cpp @@ -19,6 +19,7 @@ #include <QCoreApplication> #include <QTextCodec> +#include <QTextStream> #include <MLocale> #include <unicode/uversion.h> @@ -169,6 +170,7 @@ void Ut_MCalendar::testIcuFormatString_data() QTest::addColumn<QString>("language"); QTest::addColumn<QString>("lcMessages"); QTest::addColumn<QString>("lcTime"); + QTest::addColumn<MLocale::TimeFormat24h>("timeFormat24h"); QTest::addColumn<MLocale::CalendarType>("calendarType"); QTest::addColumn<QString>("dateShortResult"); QTest::addColumn<QString>("dateMediumResult"); @@ -178,11 +180,12 @@ void Ut_MCalendar::testIcuFormatString_data() QTest::addColumn<QString>("timeMediumResult"); QTest::addColumn<QString>("timeLongResult"); QTest::addColumn<QString>("timeFullResult"); - - QTest::newRow("de_DE, Gregorian calendar") + //-------------------------------------------------- + QTest::newRow("de_DE, Gregorian calendar, LocaleDefaultTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "fi_FI" // lc_messages does not matter << "de_DE" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << "dd.MM.yy" << "dd.MM.yyyy" @@ -192,11 +195,41 @@ void Ut_MCalendar::testIcuFormatString_data() << "HH:mm:ss" << "HH:mm:ss z" << "HH:mm:ss zzzz"; - - QTest::newRow("fi_FI, Gregorian calendar") + QTest::newRow("de_DE, Gregorian calendar, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "de_DE" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::GregorianCalendar + << "dd.MM.yy" + << "dd.MM.yyyy" + << "d. MMMM y" + << "EEEE, d. MMMM y" + << "HH:mm" + << "HH:mm:ss" + << "HH:mm:ss z" + << "HH:mm:ss zzzz"; + QTest::newRow("de_DE, Gregorian calendar, TwelveHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "de_DE" // only lc_time matters + // de_DE has 24 hours by default, override it here: + << MLocale::TwelveHourTimeFormat24h + << MLocale::GregorianCalendar + << "dd.MM.yy" + << "dd.MM.yyyy" + << "d. MMMM y" + << "EEEE, d. MMMM y" + << "hh:mm a" + << "hh:mm:ss a" + << "hh:mm:ss a z" + << "hh:mm:ss a zzzz"; + //-------------------------------------------------- + QTest::newRow("fi_FI, Gregorian calendar, LocaleDefaultTimeFormat24h") << "de_DE" // language does not matter unless lc_time is empty << "de_DE" // lc_messages does not matter << "fi_FI" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << "d.M.yyyy" << "d.M.yyyy" @@ -206,11 +239,11 @@ void Ut_MCalendar::testIcuFormatString_data() << "H.mm.ss" << "H.mm.ss z" << "H.mm.ss zzzz"; - - QTest::newRow("fi_FI, Gregorian calendar") + QTest::newRow("fi_FI, Gregorian calendar, LocaleDefaultTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "de_DE" // lc_messages does not matter << "" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << "d.M.yyyy" << "d.M.yyyy" @@ -220,11 +253,40 @@ void Ut_MCalendar::testIcuFormatString_data() << "H.mm.ss" << "H.mm.ss z" << "H.mm.ss zzzz"; - - QTest::newRow("fi_FI, Islamic calendar") + QTest::newRow("fi_FI, Gregorian calendar, TwentyFourHourTimeFormat24h") + << "de_DE" // language does not matter unless lc_time is empty + << "de_DE" // lc_messages does not matter + << "fi_FI" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::GregorianCalendar + << "d.M.yyyy" + << "d.M.yyyy" + << "d. MMMM y" + << "cccc d. MMMM y" + << "H.mm" + << "H.mm.ss" + << "H.mm.ss z" + << "H.mm.ss zzzz"; + QTest::newRow("fi_FI, Gregorian calendar, TwelveHourTimeFormat24h") + << "de_DE" // language does not matter unless lc_time is empty + << "de_DE" // lc_messages does not matter + << "fi_FI" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::GregorianCalendar + << "d.M.yyyy" + << "d.M.yyyy" + << "d. MMMM y" + << "cccc d. MMMM y" + << "h.mm a" + << "h.mm.ss a" + << "h.mm.ss a z" + << "h.mm.ss a zzzz"; + //-------------------------------------------------- + QTest::newRow("fi_FI, Islamic calendar, LocaleDefaultTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "de_DE" // lc_messages does not matter << "" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::IslamicCalendar << "d.M.yyyy" << "d.M.yyyy" @@ -234,11 +296,40 @@ void Ut_MCalendar::testIcuFormatString_data() << "H.mm.ss" << "H.mm.ss z" << "H.mm.ss zzzz"; - - QTest::newRow("Arabic, Gregorian calendar") + QTest::newRow("fi_FI, Islamic calendar, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "de_DE" // lc_messages does not matter + << "" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::IslamicCalendar + << "d.M.yyyy" + << "d.M.yyyy" + << "d. MMMM y" + << "cccc d. MMMM y" + << "H.mm" + << "H.mm.ss" + << "H.mm.ss z" + << "H.mm.ss zzzz"; + QTest::newRow("fi_FI, Islamic calendar, TwelveHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "de_DE" // lc_messages does not matter + << "" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::IslamicCalendar + << "d.M.yyyy" + << "d.M.yyyy" + << "d. MMMM y" + << "cccc d. MMMM y" + << "h.mm a" + << "h.mm.ss a" + << "h.mm.ss a z" + << "h.mm.ss a zzzz"; + //-------------------------------------------------- + QTest::newRow("Arabic, Gregorian calendar, LocaleDefaultTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "de_DE" // lc_messages does not matter << "ar_EG" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << "d/M/yyyy" // contains U+200F RIGHT-TO-LEFT MARK << "dd/MM/yyyy" // contains U+200F RIGHT-TO-LEFT MARK @@ -248,11 +339,40 @@ void Ut_MCalendar::testIcuFormatString_data() << "h:mm:ss a" << "z h:mm:ss a" << "zzzz h:mm:ss a"; - - QTest::newRow("Arabic, Islamic calendar") + QTest::newRow("Arabic, Gregorian calendar, TwelveHourTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "de_DE" // lc_messages does not matter << "ar_EG" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::GregorianCalendar + << "d/M/yyyy" // contains U+200F RIGHT-TO-LEFT MARK + << "dd/MM/yyyy" // contains U+200F RIGHT-TO-LEFT MARK + << "d MMMM، y" + << "EEEE، d MMMM، y" + << "h:mm a" + << "h:mm:ss a" + << "z h:mm:ss a" + << "zzzz h:mm:ss a"; + QTest::newRow("Arabic, Gregorian calendar, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "de_DE" // lc_messages does not matter + << "ar_EG" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::GregorianCalendar + << "d/M/yyyy" // contains U+200F RIGHT-TO-LEFT MARK + << "dd/MM/yyyy" // contains U+200F RIGHT-TO-LEFT MARK + << "d MMMM، y" + << "EEEE، d MMMM، y" + << "H:mm" + << "H:mm:ss" + << "z H:mm:ss" + << "zzzz H:mm:ss"; + //-------------------------------------------------- + QTest::newRow("Arabic, Islamic calendar, LocaleDefaultTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "de_DE" // lc_messages does not matter + << "ar_EG" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::IslamicCalendar << "d/M/yyyy" // contains U+200F RIGHT-TO-LEFT MARK << "dd/MM/yyyy" // contains U+200F RIGHT-TO-LEFT MARK @@ -262,11 +382,40 @@ void Ut_MCalendar::testIcuFormatString_data() << "h:mm:ss a" << "z h:mm:ss a" << "zzzz h:mm:ss a"; - - QTest::newRow("ja_JP, Gregorian calendar") + QTest::newRow("Arabic, Islamic calendar, TwelveHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "de_DE" // lc_messages does not matter + << "ar_EG" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::IslamicCalendar + << "d/M/yyyy" // contains U+200F RIGHT-TO-LEFT MARK + << "dd/MM/yyyy" // contains U+200F RIGHT-TO-LEFT MARK + << "d MMMM، y" + << "EEEE، d MMMM، y" + << "h:mm a" + << "h:mm:ss a" + << "z h:mm:ss a" + << "zzzz h:mm:ss a"; + QTest::newRow("Arabic, Islamic calendar, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "de_DE" // lc_messages does not matter + << "ar_EG" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::IslamicCalendar + << "d/M/yyyy" // contains U+200F RIGHT-TO-LEFT MARK + << "dd/MM/yyyy" // contains U+200F RIGHT-TO-LEFT MARK + << "d MMMM، y" + << "EEEE، d MMMM، y" + << "H:mm" + << "H:mm:ss" + << "z H:mm:ss" + << "zzzz H:mm:ss"; + //-------------------------------------------------- + QTest::newRow("ja_JP, Gregorian calendar, LocaleDefaultTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "fi_FI" // lc_messages does not matter << "ja_JP" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << "yy/MM/dd" << "yyyy/MM/dd" @@ -276,11 +425,40 @@ void Ut_MCalendar::testIcuFormatString_data() << "H:mm:ss" << "H:mm:ss z" << "H時mm分ss秒 zzzz"; - - QTest::newRow("ja_JP, Japanese calendar") + QTest::newRow("ja_JP, Gregorian calendar, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "ja_JP" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::GregorianCalendar + << "yy/MM/dd" + << "yyyy/MM/dd" + << "y年M月d日" + << "y年M月d日EEEE" + << "H:mm" + << "H:mm:ss" + << "H:mm:ss z" + << "H時mm分ss秒 zzzz"; + QTest::newRow("ja_JP, Gregorian calendar, TwelveHourTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "fi_FI" // lc_messages does not matter << "ja_JP" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::GregorianCalendar + << "yy/MM/dd" + << "yyyy/MM/dd" + << "y年M月d日" + << "y年M月d日EEEE" + << "ah:mm" + << "ah:mm:ss" + << "ah:mm:ss z" + << "ah時mm分ss秒 zzzz"; + //-------------------------------------------------- + QTest::newRow("ja_JP, Japanese calendar, LocaleDefaultTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "ja_JP" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::JapaneseCalendar << "Gyy/MM/dd" << "Gyy/MM/dd" @@ -290,11 +468,12 @@ void Ut_MCalendar::testIcuFormatString_data() << "H:mm:ss" << "H:mm:ss z" << "H時mm分ss秒 zzzz"; - - QTest::newRow("zh_CN, Gregorian calendar") + //-------------------------------------------------- + QTest::newRow("zh_CN, Gregorian calendar, LocaleDefaultTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "fi_FI" // lc_messages does not matter << "zh_CN" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << "yy-M-d" << "yyyy-M-d" @@ -304,11 +483,40 @@ void Ut_MCalendar::testIcuFormatString_data() << "ah:mm:ss" << "zah时mm分ss秒" << "zzzzah时mm分ss秒"; - - QTest::newRow("zh_CN, Chinese calendar") + QTest::newRow("zh_CN, Gregorian calendar, TwelveHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "zh_CN" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::GregorianCalendar + << "yy-M-d" + << "yyyy-M-d" + << "y年M月d日" + << "y年M月d日EEEE" + << "ah:mm" + << "ah:mm:ss" + << "zah时mm分ss秒" + << "zzzzah时mm分ss秒"; + QTest::newRow("zh_CN, Gregorian calendar, TwentyFourHourTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "fi_FI" // lc_messages does not matter << "zh_CN" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::GregorianCalendar + << "yy-M-d" + << "yyyy-M-d" + << "y年M月d日" + << "y年M月d日EEEE" + << "H:mm" + << "H:mm:ss" + << "zH时mm分ss秒" + << "zzzzH时mm分ss秒"; + //-------------------------------------------------- + QTest::newRow("zh_CN, Chinese calendar, LocaleDefaultTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "zh_CN" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::ChineseCalendar << "y'x'G-Ml-d" << "y'x'G-Ml-d" @@ -318,11 +526,40 @@ void Ut_MCalendar::testIcuFormatString_data() << "HH:mm:ss" << "HH:mm:ss z" << "HH:mm:ss zzzz"; - - QTest::newRow("th_TH, Gregorian calendar") + QTest::newRow("zh_CN, Chinese calendar, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "zh_CN" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::ChineseCalendar + << "y'x'G-Ml-d" + << "y'x'G-Ml-d" + << "y'x'G-Ml-d" + << "EEEE y'x'G-Ml-d" + << "HH:mm" + << "HH:mm:ss" + << "HH:mm:ss z" + << "HH:mm:ss zzzz"; + QTest::newRow("zh_CN, Chinese calendar, TwelveHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "zh_CN" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::ChineseCalendar + << "y'x'G-Ml-d" + << "y'x'G-Ml-d" + << "y'x'G-Ml-d" + << "EEEE y'x'G-Ml-d" + << "ahh:mm" + << "ahh:mm:ss" + << "ahh:mm:ss z" + << "ahh:mm:ss zzzz"; + //-------------------------------------------------- + QTest::newRow("th_TH, Gregorian calendar, LocaleDefaultTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "fi_FI" // lc_messages does not matter << "th_TH" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << "d/M/yyyy" << "d MMM y" @@ -332,11 +569,40 @@ void Ut_MCalendar::testIcuFormatString_data() << "H:mm:ss" << "H นาฬิกา m นาที ss วินาที z" << "H นาฬิกา m นาที ss วินาที zzzz"; - - QTest::newRow("th_TH, Buddhist calendar") + QTest::newRow("th_TH, Gregorian calendar, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "th_TH" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::GregorianCalendar + << "d/M/yyyy" + << "d MMM y" + << "d MMMM y" + << "EEEEที่ d MMMM G y" + << "H:mm" + << "H:mm:ss" + << "H นาฬิกา m นาที ss วินาที z" + << "H นาฬิกา m นาที ss วินาที zzzz"; + QTest::newRow("th_TH, Gregorian calendar, TwelveHourTimeFormat24h") << "fi_FI" // language does not matter unless lc_time is empty << "fi_FI" // lc_messages does not matter << "th_TH" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::GregorianCalendar + << "d/M/yyyy" + << "d MMM y" + << "d MMMM y" + << "EEEEที่ d MMMM G y" + << "h:mm a" + << "h:mm:ss a" + << "h นาฬิกา m นาที ss วินาที a z" + << "h นาฬิกา m นาที ss วินาที a zzzz"; + //-------------------------------------------------- + QTest::newRow("th_TH, Buddhist calendar, LocaleDefaultTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "th_TH" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h << MLocale::BuddhistCalendar << "d/M/yyyy" << "d MMM y" @@ -346,6 +612,163 @@ void Ut_MCalendar::testIcuFormatString_data() << "H:mm:ss" << "H นาฬิกา m นาที ss วินาที z" << "H นาฬิกา m นาที ss วินาที zzzz"; + QTest::newRow("th_TH, Buddhist calendar, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "th_TH" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::BuddhistCalendar + << "d/M/yyyy" + << "d MMM y" + << "d MMMM y" + << "EEEEที่ d MMMM G y" + << "H:mm" + << "H:mm:ss" + << "H นาฬิกา m นาที ss วินาที z" + << "H นาฬิกา m นาที ss วินาที zzzz"; + QTest::newRow("th_TH, Buddhist calendar, TwelveHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "th_TH" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::BuddhistCalendar + << "d/M/yyyy" + << "d MMM y" + << "d MMMM y" + << "EEEEที่ d MMMM G y" + << "h:mm a" + << "h:mm:ss a" + << "h นาฬิกา m นาที ss วินาที a z" + << "h นาฬิกา m นาที ss วินาที a zzzz"; + //-------------------------------------------------- + QTest::newRow("de_BE, Gregorian, LocaleDefaultTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "de_BE" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h + << MLocale::GregorianCalendar + << "d/MM/yy" + << "dd.MM.yyyy" + << "d MMMM y" + << "EEEE d MMMM y" + << "HH:mm" + << "HH:mm:ss" + << "HH:mm:ss z" + << "HH 'h' mm 'min' ss 's' zzzz"; + QTest::newRow("de_BE, Gregorian, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "de_BE" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::GregorianCalendar + << "d/MM/yy" + << "dd.MM.yyyy" + << "d MMMM y" + << "EEEE d MMMM y" + << "HH:mm" + << "HH:mm:ss" + << "HH:mm:ss z" + << "HH 'h' mm 'min' ss 's' zzzz"; + QTest::newRow("de_BE, Gregorian, TwelveHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "de_BE" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::GregorianCalendar + << "d/MM/yy" + << "dd.MM.yyyy" + << "d MMMM y" + << "EEEE d MMMM y" + << "hh:mm a" + << "hh:mm:ss a" + << "hh:mm:ss a z" + << "hh 'h' mm 'min' ss 's' a zzzz"; + //-------------------------------------------------- + QTest::newRow("en_BE, Gregorian, LocaleDefaultTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "en_BE" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h + << MLocale::GregorianCalendar + << "dd/MM/yy" + << "dd MMM y" + << "d MMM y" + << "EEEE d MMMM y" + << "HH:mm" + << "HH:mm:ss" + << "HH:mm:ss z" + << "HH 'h' mm 'min' ss 's' zzzz"; + QTest::newRow("en_BE, Gregorian, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "en_BE" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::GregorianCalendar + << "dd/MM/yy" + << "dd MMM y" + << "d MMM y" + << "EEEE d MMMM y" + << "HH:mm" + << "HH:mm:ss" + << "HH:mm:ss z" + << "HH 'h' mm 'min' ss 's' zzzz"; + QTest::newRow("en_BE, Gregorian, TwelveHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "en_BE" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::GregorianCalendar + << "dd/MM/yy" + << "dd MMM y" + << "d MMM y" + << "EEEE d MMMM y" + << "hh:mm a" + << "hh:mm:ss a" + << "hh:mm:ss a z" + << "hh 'h' mm 'min' ss 's' a zzzz"; + //-------------------------------------------------- + QTest::newRow("eo, Gregorian, LocaleDefaultTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "eo" // only lc_time matters + << MLocale::LocaleDefaultTimeFormat24h + << MLocale::GregorianCalendar + << "yy-MM-dd" + << "y-MMM-dd" + << "y-MMMM-dd" + << "EEEE, d-'a' 'de' MMMM y" + << "HH:mm" + << "HH:mm:ss" + << "HH:mm:ss z" + << "H-'a' 'horo' 'kaj' m:ss zzzz"; + QTest::newRow("eo, Gregorian, TwentyFourHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "eo" // only lc_time matters + << MLocale::TwentyFourHourTimeFormat24h + << MLocale::GregorianCalendar + << "yy-MM-dd" + << "y-MMM-dd" + << "y-MMMM-dd" + << "EEEE, d-'a' 'de' MMMM y" + << "HH:mm" + << "HH:mm:ss" + << "HH:mm:ss z" + << "H-'a' 'horo' 'kaj' m:ss zzzz"; + QTest::newRow("eo, Gregorian, TwelveHourTimeFormat24h") + << "fi_FI" // language does not matter unless lc_time is empty + << "fi_FI" // lc_messages does not matter + << "eo" // only lc_time matters + << MLocale::TwelveHourTimeFormat24h + << MLocale::GregorianCalendar + << "yy-MM-dd" + << "y-MMM-dd" + << "y-MMMM-dd" + << "EEEE, d-'a' 'de' MMMM y" + << "hh:mm a" + << "hh:mm:ss a" + << "hh:mm:ss a z" + << "h-'a' 'horo' 'kaj' m:ss a zzzz"; } void Ut_MCalendar::testIcuFormatString() @@ -353,6 +776,7 @@ void Ut_MCalendar::testIcuFormatString() QFETCH(QString, language); QFETCH(QString, lcMessages); QFETCH(QString, lcTime); + QFETCH(MLocale::TimeFormat24h, timeFormat24h); QFETCH(MLocale::CalendarType, calendarType); QFETCH(QString, dateShortResult); QFETCH(QString, dateMediumResult); @@ -367,6 +791,7 @@ void Ut_MCalendar::testIcuFormatString() QCOMPARE(MLocale::dataPaths(), (QStringList() << "/usr/share/meegotouch/icu")); locale.setCategoryLocale(MLocale::MLcMessages, lcMessages); locale.setCategoryLocale(MLocale::MLcTime, lcTime); + locale.setTimeFormat24h(timeFormat24h); QList<QString> dateResults; dateResults << QString("") @@ -387,7 +812,7 @@ void Ut_MCalendar::testIcuFormatString() ++timeType) { QString expectedResult; if (dateType == MLocale::DateNone && timeType == MLocale::TimeNone) - expectedResult = QString("yyyyMMdd hh:mm a"); + expectedResult = QString("irrelevant"); else if (dateType == MLocale::DateNone) expectedResult = timeResults[timeType]; else if (timeType == MLocale::TimeNone) @@ -412,9 +837,14 @@ void Ut_MCalendar::testIcuFormatString() calendarType); QTextStream debugStream(stderr); debugStream.setCodec("UTF-8"); - debugStream << "dateType: " << dateType << " timeType: " << timeType - << " expectedResult: " << expectedResult << " result: " << result << "\n"; - QCOMPARE(result, expectedResult); + debugStream << lcTime + << " timeFormat24h: " << timeFormat24h + << " dateType: " << dateType << " timeType: " << timeType + << " expectedResult: " << expectedResult + << " result: " << result + << "\n"; + if (expectedResult != "irrelevant") + QCOMPARE(result, expectedResult); } } } @@ -669,6 +1099,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() QTest::addColumn<QString>("lcTime"); QTest::addColumn<QString>("lcNumeric"); QTest::addColumn<QString>("timeZone"); + QTest::addColumn<MLocale::TimeFormat24h>("timeFormat24h"); QTest::addColumn<MLocale::CalendarType>("calType"); QTest::addColumn<int>("year"); QTest::addColumn<int>("month"); @@ -688,6 +1119,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("de_DE") // only this matters << QString("fi_FI") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -706,6 +1138,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("fi_FI") // only this matters << QString("de_DE") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -724,6 +1157,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("en_GB") // only this matters << QString("fi_FI") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -742,6 +1176,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("nn_NO") // only this matters << QString("fi_FI") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -760,6 +1195,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("nb_NO") // only this matters << QString("fi_FI") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -778,6 +1214,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("no_NO") // only this matters << QString("fi_FI") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -796,6 +1233,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("ja_JP") // only this matters << QString("fi_FI") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -814,6 +1252,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("ja_JP") // only this matters << QString("fi_FI") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -832,6 +1271,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("zh_CN") // only this matters << QString("fi_FI") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -850,6 +1290,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("ar_EG") // only this matters << QString("fi_FI") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -868,6 +1309,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar_data() << QString("th_TH") // only this matters << QString("fi_FI") << "Europe/Helsinki" + << MLocale::LocaleDefaultTimeFormat24h << MLocale::GregorianCalendar << 2008 << 7 @@ -889,6 +1331,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar() QFETCH(QString, lcTime); QFETCH(QString, lcNumeric); QFETCH(QString, timeZone); + QFETCH(MLocale::TimeFormat24h, timeFormat24h); QFETCH(MLocale::CalendarType, calType); QFETCH(int, year); QFETCH(int, month); @@ -907,6 +1350,7 @@ void Ut_MCalendar::testMLocaleCalendarConversionsFromMCalendar() locale.setCategoryLocale(MLocale::MLcMessages, lcMessages); locale.setCategoryLocale(MLocale::MLcTime, lcTime); locale.setCategoryLocale(MLocale::MLcNumeric, lcNumeric); + locale.setTimeFormat24h(timeFormat24h); MCalendar::setSystemTimeZone("Europe/Helsinki"); MCalendar mcal(calType); mcal.setDate(year, month, day); diff --git a/tests/ut_mcalendar/ut_mcalendar.h b/tests/ut_mcalendar/ut_mcalendar.h index f7903359..3d098457 100644 --- a/tests/ut_mcalendar/ut_mcalendar.h +++ b/tests/ut_mcalendar/ut_mcalendar.h @@ -26,6 +26,21 @@ #include <MLocale> #include <MCalendar> +#ifdef HAVE_ICU +#include <unicode/unistr.h> +#include <unicode/ucal.h> +#include <unicode/coll.h> +#include <unicode/fieldpos.h> +#include <unicode/datefmt.h> +#include <unicode/calendar.h> +#include <unicode/smpdtfmt.h> // SimpleDateFormat +#include <unicode/numfmt.h> +#include <unicode/uloc.h> +#include <unicode/dtfmtsym.h> // date format symbols +#include <unicode/putil.h> // u_setDataDirectory +#endif + +Q_DECLARE_METATYPE(MLocale::TimeFormat24h); Q_DECLARE_METATYPE(MLocale::CalendarType); Q_DECLARE_METATYPE(MLocale); |