Ticket #4418: 4418_duration_l18n_v3.patch

File 4418_duration_l18n_v3.patch, 6.3 KB (added by Imarok, 7 years ago)

Don't use Duration

  • binaries/data/mods/public/gui/common/functions_utility.js

     
    132132        var format = translate("mm:ss");
    133133    else
    134134        var format = translate("HH:mm:ss");
    135     return Engine.FormatMillisecondsIntoDateString(time, format);
     135    return Engine.FormatMillisecondsIntoDateStringGMT(time, format);
    136136}
    137137
    138138function removeDupes(array)
  • source/i18n/L10n.cpp

     
    375375    return std::string(utf8Date, sink.NumberOfBytesWritten());
    376376}
    377377
    378 std::string L10n::FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString) const
     378std::string L10n::FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString, bool useLocalTimezone) const
    379379{
    380380    UErrorCode status = U_ZERO_ERROR;
    381381    UnicodeString dateString;
     
    386386    if (U_FAILURE(status))
    387387        LOGERROR("Error creating SimpleDateFormat: %s", u_errorName(status));
    388388
    389     const TimeZone* timeZone = TimeZone::createDefault();
     389    const TimeZone* timeZone = useLocalTimezone ? TimeZone::createDefault() : TimeZone::getGMT() ;
    390390
    391391    status = U_ZERO_ERROR;
    392392    Calendar* calendar = Calendar::createInstance(*timeZone, currentLocale, status);
  • source/i18n/L10n.h

     
    427427    std::string LocalizeDateTime(const UDate& dateTime, const DateTimeType& type, const DateFormat::EStyle& style) const;
    428428
    429429    /**
    430      * Returns the specified date converted to the local timezone using the specified date format.
     430     * Returns the specified date using the specified date format.
    431431     *
    432432     * @param milliseconds Date specified as a UNIX timestamp in milliseconds
    433433     *        (not seconds).
     
    435435     *        symbols. Usually, you internationalize the format string and
    436436     *        get it translated before you pass it to
    437437     *        FormatMillisecondsIntoDateString().
     438     * @param useLocalTimezone Boolean usefull for durations; default: true
    438439     * @return String containing the specified date with the specified date
    439440     *         format.
    440441     *
     
    441442     * @sa http://en.wikipedia.org/wiki/Unix_time
    442443     * @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
    443444     */
    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;
    445446
    446447    /**
    447448     * Returns the specified floating-point number as a string, with the number
  • source/i18n/scripting/JSInterface_L10n.cpp

     
    7474    return wstring_from_utf8(g_L10n.FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString)));
    7575}
    7676
     77// Return a localized version of a duration or a time in GMT given in milliseconds.
     78std::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
    7783// Return a localized version of the given decimal number.
    7884std::wstring JSI_L10n::FormatDecimalNumberIntoString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), double number)
    7985{
     
    160166    scriptInterface.RegisterFunction<std::wstring, std::wstring, &TranslateLines>("TranslateLines");
    161167    scriptInterface.RegisterFunction<std::vector<std::wstring>, std::vector<std::wstring>, &TranslateArray>("TranslateArray");
    162168    scriptInterface.RegisterFunction<std::wstring, UDate, std::wstring, &FormatMillisecondsIntoDateString>("FormatMillisecondsIntoDateString");
     169    scriptInterface.RegisterFunction<std::wstring, UDate, std::wstring, &FormatMillisecondsIntoDateStringGMT>("FormatMillisecondsIntoDateStringGMT");
    163170    scriptInterface.RegisterFunction<std::wstring, double, &FormatDecimalNumberIntoString>("FormatDecimalNumberIntoString");
    164171
    165172    scriptInterface.RegisterFunction<std::vector<std::string>, &GetSupportedLocaleBaseNames>("GetSupportedLocaleBaseNames");
  • source/i18n/scripting/JSInterface_L10n.h

     
    175175    std::wstring FormatMillisecondsIntoDateString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString);
    176176
    177177    /**
     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    /**
    178200     * Returns the specified floating-point number as a string, with the number
    179201     * formatted as a decimal number using the
    180202     * @link L10n::GetCurrentLocale() current locale@endlink.