Ticket #2938: hoursDisplay.patch

File hoursDisplay.patch, 2.3 KB (added by Justin, 9 years ago)

Adds hours display to the game time

  • source/i18n/L10n.cpp

     
    3636#include "ps/Filesystem.h"
    3737#include "ps/GameSetup/GameSetup.h"
    3838
    39 
    4039static Status ReloadChangedFileCB(void* param, const VfsPath& path)
    4140{
    4241    return static_cast<L10n*>(param)->ReloadChangedFile(path);
     
    402401
    403402std::string L10n::FormatMillisecondsIntoDateString(UDate milliseconds, const std::string& formatString)
    404403{
    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;
    408407
    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));
    412413
    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);
    417424
    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;
    422428
    423     return std::string(utf8Date, sink.NumberOfBytesWritten());
     429    return resultString;
    424430}
    425431
    426432std::string L10n::FormatDecimalNumberIntoString(double number)