Ticket #2938: hoursDisplay.patch
File hoursDisplay.patch, 2.3 KB (added by , 9 years ago) |
---|
-
source/i18n/L10n.cpp
36 36 #include "ps/Filesystem.h" 37 37 #include "ps/GameSetup/GameSetup.h" 38 38 39 40 39 static Status ReloadChangedFileCB(void* param, const VfsPath& path) 41 40 { 42 41 return static_cast<L10n*>(param)->ReloadChangedFile(path); … … 402 401 403 402 std::string L10n::FormatMillisecondsIntoDateString(UDate milliseconds, const std::string& formatString) 404 403 { 405 UErrorCode success = U_ZERO_ERROR;406 UnicodeString utf16Date;407 UnicodeString utf16LocalizedDateTimeFormat = UnicodeString::fromUTF8(formatString.c_str());404 UErrorCode status; 405 UnicodeString dateString; 406 CStr resultString; 408 407 409 // The format below should never reach the user, the one that matters is the 410 // one from the formatString parameter. 411 UnicodeString utf16SourceDateTimeFormat = UnicodeString::fromUTF8("No format specified (you should not be seeing this string!)"); 408 UnicodeString unicodeFormat = UnicodeString::fromUTF8(formatString.c_str()); 409 SimpleDateFormat* dateFormat = new SimpleDateFormat(unicodeFormat, status); 410 411 if(U_FAILURE(status)) 412 LOGERROR(L"Error creating SimpleDateFormat: %s", u_errorName(status)); 412 413 413 SimpleDateFormat* dateFormatter = new SimpleDateFormat(utf16SourceDateTimeFormat, currentLocale, success); 414 dateFormatter->applyLocalizedPattern(utf16LocalizedDateTimeFormat, success); 415 dateFormatter->format(milliseconds, utf16Date); 416 delete dateFormatter; 414 TimeZone* timeZone = TimeZone::createTimeZone("GMT"); 415 416 Calendar* calendar = Calendar::createInstance(timeZone, currentLocale, status); 417 418 if(U_FAILURE(status)) 419 LOGERROR(L"Error creating calendar: %s", u_errorName(status)); 420 421 dateFormat->adoptCalendar(calendar); 422 dateFormat->format(milliseconds, dateString); 423 dateString.toUTF8String(resultString); 417 424 418 char utf8Date[512]; 419 CheckedArrayByteSink sink(utf8Date, ARRAY_SIZE(utf8Date)); 420 utf16Date.toUTF8(sink); 421 ENSURE(!sink.Overflowed()); 425 //We only need to delete the dateFormat pointer, because it accepts 426 //ownership of calendar and timeZone. 427 delete dateFormat; 422 428 423 return std::string(utf8Date, sink.NumberOfBytesWritten());429 return resultString; 424 430 } 425 431 426 432 std::string L10n::FormatDecimalNumberIntoString(double number)