Ticket #4418: 4418_duration_l18n_v3.patch
File 4418_duration_l18n_v3.patch, 6.3 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.FormatMillisecondsIntoDateString (time, format);135 return Engine.FormatMillisecondsIntoDateStringGMT(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 useLocalTimezone) 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 = useLocalTimezone ? TimeZone::createDefault() : TimeZone::getGMT() ; 390 390 391 391 status = U_ZERO_ERROR; 392 392 Calendar* calendar = Calendar::createInstance(*timeZone, currentLocale, status); -
source/i18n/L10n.h
427 427 std::string LocalizeDateTime(const UDate& dateTime, const DateTimeType& type, const DateFormat::EStyle& style) const; 428 428 429 429 /** 430 * Returns the specified date converted to the local timezoneusing the specified date format.430 * Returns the specified date using the specified date format. 431 431 * 432 432 * @param milliseconds Date specified as a UNIX timestamp in milliseconds 433 433 * (not seconds). … … 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 useLocalTimezone Boolean usefull for durations; default: true 438 439 * @return String containing the specified date with the specified date 439 440 * format. 440 441 * … … 441 442 * @sa http://en.wikipedia.org/wiki/Unix_time 442 443 * @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table 443 444 */ 444 std::string FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString ) const;445 std::string FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString, bool useLocalTimezone = true) const; 445 446 446 447 /** 447 448 * 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 or a time in GMT given in milliseconds. 78 std::wstring JSI_L10n::FormatMillisecondsIntoDateStringGMT(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString) 79 { 80 return wstring_from_utf8(g_L10n.FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString), false)); 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, &FormatMillisecondsIntoDateStringGMT>("FormatMillisecondsIntoDateStringGMT"); 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 date converted to GMT 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 FormatMillisecondsIntoDateStringGMT(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.