Ticket #4418: 4418_duration_l18n.patch
File 4418_duration_l18n.patch, 5.9 KB (added by , 7 years ago) |
---|
-
binaries/data/mods/public/gui/common/functions_utility.js
132 132 var format = translate("mm:ss"); 133 133 else 134 134 var format = translate("HH:mm:ss"); 135 return Engine.FormatMillisecondsIntoD ateString(time, format);135 return Engine.FormatMillisecondsIntoDurationString(time, format); 136 136 } 137 137 138 138 function removeDupes(array) -
source/i18n/L10n.cpp
375 375 return std::string(utf8Date, sink.NumberOfBytesWritten()); 376 376 } 377 377 378 std::string L10n::FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString ) const378 std::string L10n::FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString, bool isDuration) const 379 379 { 380 380 UErrorCode status = U_ZERO_ERROR; 381 381 UnicodeString dateString; … … 386 386 if (U_FAILURE(status)) 387 387 LOGERROR("Error creating SimpleDateFormat: %s", u_errorName(status)); 388 388 389 const TimeZone* timeZone = TimeZone::createDefault();389 const TimeZone* timeZone = isDuration ? TimeZone::getGMT() : TimeZone::createDefault(); 390 390 391 391 status = U_ZERO_ERROR; 392 392 Calendar* calendar = Calendar::createInstance(*timeZone, currentLocale, status); -
source/i18n/L10n.h
435 435 * symbols. Usually, you internationalize the format string and 436 436 * get it translated before you pass it to 437 437 * FormatMillisecondsIntoDateString(). 438 * @param isDuration Boolean if the date is a duration don't convert to 439 * the local timezone; default: false 438 440 * @return String containing the specified date with the specified date 439 441 * format. 440 442 * … … 441 443 * @sa http://en.wikipedia.org/wiki/Unix_time 442 444 * @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table 443 445 */ 444 std::string FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString ) const;446 std::string FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString, bool isDuration = false) const; 445 447 446 448 /** 447 449 * Returns the specified floating-point number as a string, with the number -
source/i18n/scripting/JSInterface_L10n.cpp
74 74 return wstring_from_utf8(g_L10n.FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString))); 75 75 } 76 76 77 // Return a localized version of a duration given in milliseconds. 78 std::wstring JSI_L10n::FormatMillisecondsIntoDurationString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString) 79 { 80 return wstring_from_utf8(g_L10n.FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString), true)); 81 } 82 77 83 // Return a localized version of the given decimal number. 78 84 std::wstring JSI_L10n::FormatDecimalNumberIntoString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), double number) 79 85 { … … 160 166 scriptInterface.RegisterFunction<std::wstring, std::wstring, &TranslateLines>("TranslateLines"); 161 167 scriptInterface.RegisterFunction<std::vector<std::wstring>, std::vector<std::wstring>, &TranslateArray>("TranslateArray"); 162 168 scriptInterface.RegisterFunction<std::wstring, UDate, std::wstring, &FormatMillisecondsIntoDateString>("FormatMillisecondsIntoDateString"); 169 scriptInterface.RegisterFunction<std::wstring, UDate, std::wstring, &FormatMillisecondsIntoDurationString>("FormatMillisecondsIntoDurationString"); 163 170 scriptInterface.RegisterFunction<std::wstring, double, &FormatDecimalNumberIntoString>("FormatDecimalNumberIntoString"); 164 171 165 172 scriptInterface.RegisterFunction<std::vector<std::string>, &GetSupportedLocaleBaseNames>("GetSupportedLocaleBaseNames"); -
source/i18n/scripting/JSInterface_L10n.h
175 175 std::wstring FormatMillisecondsIntoDateString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString); 176 176 177 177 /** 178 * Returns the specified duration using the specified date format. 179 * 180 * This is a JavaScript interface to 181 * L10n::FormatMillisecondsIntoDateString(). 182 * 183 * @param pCxPrivate JavaScript context. 184 * @param milliseconds Date specified as a UNIX timestamp in milliseconds 185 * (not seconds). If you have a JavaScript @c Date object, you can 186 * use @c Date.getTime() to obtain the UNIX time in milliseconds. 187 * @param formatString Date format string defined using ICU date formatting 188 * symbols. Usually, you internationalize the format string and 189 * get it translated before you pass it to 190 * FormatMillisecondsIntoDateString(). 191 * @return String containing the specified date with the specified date 192 * format. 193 * 194 * @sa http://en.wikipedia.org/wiki/Unix_time 195 * @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table 196 */ 197 std::wstring FormatMillisecondsIntoDurationString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString); 198 199 /** 178 200 * Returns the specified floating-point number as a string, with the number 179 201 * formatted as a decimal number using the 180 202 * @link L10n::GetCurrentLocale() current locale@endlink.