Durations over 1 hour aren't displayed correctly
Reviewed by: elexis Differential Revision: https://code.wildfiregames.com/D44 refs #4418, #3350 This was SVN commit r19180.
This commit is contained in:
parent
9b819645f5
commit
a74fcdcb35
@ -132,7 +132,7 @@ function timeToString(time)
|
|||||||
var format = translate("mm:ss");
|
var format = translate("mm:ss");
|
||||||
else
|
else
|
||||||
var format = translate("HH:mm:ss");
|
var format = translate("HH:mm:ss");
|
||||||
return Engine.FormatMillisecondsIntoDateString(time, format);
|
return Engine.FormatMillisecondsIntoDateStringGMT(time, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeDupes(array)
|
function removeDupes(array)
|
||||||
|
@ -5,7 +5,7 @@ function sortDecreasingDate(a, b)
|
|||||||
|
|
||||||
function generateLabel(metadata, engineInfo)
|
function generateLabel(metadata, engineInfo)
|
||||||
{
|
{
|
||||||
let dateTimeString = Engine.FormatMillisecondsIntoDateString(metadata.time*1000, translate("yyyy-MM-dd HH:mm:ss"));
|
let dateTimeString = Engine.FormatMillisecondsIntoDateStringLocal(metadata.time*1000, translate("yyyy-MM-dd HH:mm:ss"));
|
||||||
let dateString = sprintf(translate("\\[%(date)s]"), { "date": dateTimeString });
|
let dateString = sprintf(translate("\\[%(date)s]"), { "date": dateTimeString });
|
||||||
|
|
||||||
if (engineInfo)
|
if (engineInfo)
|
||||||
|
@ -1823,7 +1823,7 @@ function addChatMessage(msg)
|
|||||||
if (Engine.ConfigDB_GetValue("user", "chat.timestamp") == "true")
|
if (Engine.ConfigDB_GetValue("user", "chat.timestamp") == "true")
|
||||||
text = sprintf(translate("%(time)s %(message)s"), {
|
text = sprintf(translate("%(time)s %(message)s"), {
|
||||||
"time": sprintf(translate("\\[%(time)s]"), {
|
"time": sprintf(translate("\\[%(time)s]"), {
|
||||||
"time": Engine.FormatMillisecondsIntoDateString(new Date().getTime(), translate("HH:mm"))
|
"time": Engine.FormatMillisecondsIntoDateStringLocal(new Date().getTime(), translate("HH:mm"))
|
||||||
}),
|
}),
|
||||||
"message": text
|
"message": text
|
||||||
});
|
});
|
||||||
|
@ -632,7 +632,7 @@ function updateGameSelection()
|
|||||||
sgGameStartTime.caption = sprintf(
|
sgGameStartTime.caption = sprintf(
|
||||||
// Translation: %(time)s is the hour and minute here.
|
// Translation: %(time)s is the hour and minute here.
|
||||||
translate("Game started at %(time)s"), {
|
translate("Game started at %(time)s"), {
|
||||||
"time": Engine.FormatMillisecondsIntoDateString(+game.startTime*1000, translate("HH:mm"))
|
"time": Engine.FormatMillisecondsIntoDateStringLocal(+game.startTime*1000, translate("HH:mm"))
|
||||||
});
|
});
|
||||||
|
|
||||||
sgNbPlayers.caption = sprintf(
|
sgNbPlayers.caption = sprintf(
|
||||||
@ -993,7 +993,7 @@ function ircFormat(msg)
|
|||||||
// Translation: Time as shown in the multiplayer lobby (when you enable it in the options page).
|
// Translation: Time as shown in the multiplayer lobby (when you enable it in the options page).
|
||||||
// For a list of symbols that you can use, see:
|
// For a list of symbols that you can use, see:
|
||||||
// https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
|
// https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
|
||||||
let timeString = Engine.FormatMillisecondsIntoDateString(time.getTime(), translate("HH:mm"));
|
let timeString = Engine.FormatMillisecondsIntoDateStringLocal(time.getTime(), translate("HH:mm"));
|
||||||
|
|
||||||
// Translation: Time prefix as shown in the multiplayer lobby (when you enable it in the options page).
|
// Translation: Time prefix as shown in the multiplayer lobby (when you enable it in the options page).
|
||||||
let timePrefixString = sprintf(translate("\\[%(time)s]"), {
|
let timePrefixString = sprintf(translate("\\[%(time)s]"), {
|
||||||
|
@ -300,7 +300,7 @@ function greyout(text, isCompatible)
|
|||||||
*/
|
*/
|
||||||
function getReplayDateTime(replay)
|
function getReplayDateTime(replay)
|
||||||
{
|
{
|
||||||
return Engine.FormatMillisecondsIntoDateString(replay.timestamp * 1000, translate("yyyy-MM-dd HH:mm"));
|
return Engine.FormatMillisecondsIntoDateStringLocal(replay.timestamp * 1000, translate("yyyy-MM-dd HH:mm"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -330,7 +330,7 @@ function getReplayMapName(replay)
|
|||||||
*/
|
*/
|
||||||
function getReplayMonth(replay)
|
function getReplayMonth(replay)
|
||||||
{
|
{
|
||||||
return Engine.FormatMillisecondsIntoDateString(replay.timestamp * 1000, translate("yyyy-MM"));
|
return Engine.FormatMillisecondsIntoDateStringLocal(replay.timestamp * 1000, translate("yyyy-MM"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -787,7 +787,7 @@ function addChatMessage(msg)
|
|||||||
let historical = {
|
let historical = {
|
||||||
"txt": formatted,
|
"txt": formatted,
|
||||||
"timePrefix": sprintf(translate("\\[%(time)s]"), {
|
"timePrefix": sprintf(translate("\\[%(time)s]"), {
|
||||||
"time": Engine.FormatMillisecondsIntoDateString(new Date().getTime(), translate("HH:mm"))
|
"time": Engine.FormatMillisecondsIntoDateStringLocal(new Date().getTime(), translate("HH:mm"))
|
||||||
}),
|
}),
|
||||||
"filter": {}
|
"filter": {}
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (c) 2016 Wildfire Games
|
/* Copyright (c) 2017 Wildfire Games
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -360,7 +360,7 @@ UDate L10n::ParseDateTime(const std::string& dateTimeString, const std::string&
|
|||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string L10n::LocalizeDateTime(const UDate& dateTime, const DateTimeType& type, const DateFormat::EStyle& style) const
|
std::string L10n::LocalizeDateTime(const UDate dateTime, const DateTimeType& type, const DateFormat::EStyle& style) const
|
||||||
{
|
{
|
||||||
UnicodeString utf16Date;
|
UnicodeString utf16Date;
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ std::string L10n::LocalizeDateTime(const UDate& dateTime, const DateTimeType& ty
|
|||||||
return std::string(utf8Date, sink.NumberOfBytesWritten());
|
return std::string(utf8Date, sink.NumberOfBytesWritten());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string L10n::FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString) const
|
std::string L10n::FormatMillisecondsIntoDateString(const UDate milliseconds, const std::string& formatString, bool useLocalTimezone) const
|
||||||
{
|
{
|
||||||
UErrorCode status = U_ZERO_ERROR;
|
UErrorCode status = U_ZERO_ERROR;
|
||||||
UnicodeString dateString;
|
UnicodeString dateString;
|
||||||
@ -386,7 +386,7 @@ std::string L10n::FormatMillisecondsIntoDateString(const UDate& milliseconds, co
|
|||||||
if (U_FAILURE(status))
|
if (U_FAILURE(status))
|
||||||
LOGERROR("Error creating SimpleDateFormat: %s", u_errorName(status));
|
LOGERROR("Error creating SimpleDateFormat: %s", u_errorName(status));
|
||||||
|
|
||||||
const TimeZone* timeZone = TimeZone::createDefault();
|
const TimeZone* timeZone = useLocalTimezone ? TimeZone::createDefault() : TimeZone::getGMT() ;
|
||||||
|
|
||||||
status = U_ZERO_ERROR;
|
status = U_ZERO_ERROR;
|
||||||
Calendar* calendar = Calendar::createInstance(*timeZone, currentLocale, status);
|
Calendar* calendar = Calendar::createInstance(*timeZone, currentLocale, status);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (c) 2016 Wildfire Games
|
/* Copyright (c) 2017 Wildfire Games
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -424,10 +424,10 @@ public:
|
|||||||
* @sa http://en.wikipedia.org/wiki/Unix_time
|
* @sa http://en.wikipedia.org/wiki/Unix_time
|
||||||
* @sa http://icu-project.org/apiref/icu4c521/classicu_1_1DateFormat.html
|
* @sa http://icu-project.org/apiref/icu4c521/classicu_1_1DateFormat.html
|
||||||
*/
|
*/
|
||||||
std::string LocalizeDateTime(const UDate& dateTime, const DateTimeType& type, const DateFormat::EStyle& style) const;
|
std::string LocalizeDateTime(const UDate dateTime, const DateTimeType& type, const DateFormat::EStyle& style) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the specified date converted to the local timezone using the specified date format.
|
* Returns the specified date using the specified date format.
|
||||||
*
|
*
|
||||||
* @param milliseconds Date specified as a UNIX timestamp in milliseconds
|
* @param milliseconds Date specified as a UNIX timestamp in milliseconds
|
||||||
* (not seconds).
|
* (not seconds).
|
||||||
@ -435,13 +435,14 @@ public:
|
|||||||
* symbols. Usually, you internationalize the format string and
|
* symbols. Usually, you internationalize the format string and
|
||||||
* get it translated before you pass it to
|
* get it translated before you pass it to
|
||||||
* FormatMillisecondsIntoDateString().
|
* FormatMillisecondsIntoDateString().
|
||||||
|
* @param useLocalTimezone Boolean useful for durations
|
||||||
* @return String containing the specified date with the specified date
|
* @return String containing the specified date with the specified date
|
||||||
* format.
|
* format.
|
||||||
*
|
*
|
||||||
* @sa http://en.wikipedia.org/wiki/Unix_time
|
* @sa http://en.wikipedia.org/wiki/Unix_time
|
||||||
* @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
|
* @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
|
||||||
*/
|
*/
|
||||||
std::string FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString) const;
|
std::string FormatMillisecondsIntoDateString(const UDate milliseconds, const std::string& formatString, bool useLocalTimezone) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the specified floating-point number as a string, with the number
|
* Returns the specified floating-point number as a string, with the number
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2015 Wildfire Games.
|
/* Copyright (C) 2017 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
@ -69,9 +69,15 @@ std::wstring JSI_L10n::GetFallbackToAvailableDictLocale(ScriptInterface::CxPriva
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return a localized version of a time given in milliseconds.
|
// Return a localized version of a time given in milliseconds.
|
||||||
std::wstring JSI_L10n::FormatMillisecondsIntoDateString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString)
|
std::wstring JSI_L10n::FormatMillisecondsIntoDateStringLocal(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString)
|
||||||
{
|
{
|
||||||
return wstring_from_utf8(g_L10n.FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString)));
|
return wstring_from_utf8(g_L10n.FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a localized version of a duration or a time in GMT given in milliseconds.
|
||||||
|
std::wstring JSI_L10n::FormatMillisecondsIntoDateStringGMT(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString)
|
||||||
|
{
|
||||||
|
return wstring_from_utf8(g_L10n.FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a localized version of the given decimal number.
|
// Return a localized version of the given decimal number.
|
||||||
@ -159,7 +165,8 @@ void JSI_L10n::RegisterScriptFunctions(ScriptInterface& scriptInterface)
|
|||||||
scriptInterface.RegisterFunction<std::wstring, std::string, std::wstring, std::wstring, int, &TranslatePluralWithContext>("TranslatePluralWithContext");
|
scriptInterface.RegisterFunction<std::wstring, std::string, std::wstring, std::wstring, int, &TranslatePluralWithContext>("TranslatePluralWithContext");
|
||||||
scriptInterface.RegisterFunction<std::wstring, std::wstring, &TranslateLines>("TranslateLines");
|
scriptInterface.RegisterFunction<std::wstring, std::wstring, &TranslateLines>("TranslateLines");
|
||||||
scriptInterface.RegisterFunction<std::vector<std::wstring>, std::vector<std::wstring>, &TranslateArray>("TranslateArray");
|
scriptInterface.RegisterFunction<std::vector<std::wstring>, std::vector<std::wstring>, &TranslateArray>("TranslateArray");
|
||||||
scriptInterface.RegisterFunction<std::wstring, UDate, std::wstring, &FormatMillisecondsIntoDateString>("FormatMillisecondsIntoDateString");
|
scriptInterface.RegisterFunction<std::wstring, UDate, std::wstring, &FormatMillisecondsIntoDateStringLocal>("FormatMillisecondsIntoDateStringLocal");
|
||||||
|
scriptInterface.RegisterFunction<std::wstring, UDate, std::wstring, &FormatMillisecondsIntoDateStringGMT>("FormatMillisecondsIntoDateStringGMT");
|
||||||
scriptInterface.RegisterFunction<std::wstring, double, &FormatDecimalNumberIntoString>("FormatDecimalNumberIntoString");
|
scriptInterface.RegisterFunction<std::wstring, double, &FormatDecimalNumberIntoString>("FormatDecimalNumberIntoString");
|
||||||
|
|
||||||
scriptInterface.RegisterFunction<std::vector<std::string>, &GetSupportedLocaleBaseNames>("GetSupportedLocaleBaseNames");
|
scriptInterface.RegisterFunction<std::vector<std::string>, &GetSupportedLocaleBaseNames>("GetSupportedLocaleBaseNames");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2016 Wildfire Games.
|
/* Copyright (C) 2017 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
@ -172,7 +172,29 @@ namespace JSI_L10n
|
|||||||
* @sa http://en.wikipedia.org/wiki/Unix_time
|
* @sa http://en.wikipedia.org/wiki/Unix_time
|
||||||
* @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
|
* @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
|
||||||
*/
|
*/
|
||||||
std::wstring FormatMillisecondsIntoDateString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString);
|
std::wstring FormatMillisecondsIntoDateStringLocal(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the specified date in GMT using the specified date format.
|
||||||
|
*
|
||||||
|
* This is a JavaScript interface to
|
||||||
|
* L10n::FormatMillisecondsIntoDateString().
|
||||||
|
*
|
||||||
|
* @param pCxPrivate JavaScript context.
|
||||||
|
* @param milliseconds Date specified as a UNIX timestamp in milliseconds
|
||||||
|
* (not seconds). If you have a JavaScript @c Date object, you can
|
||||||
|
* use @c Date.getTime() to obtain the UNIX time in milliseconds.
|
||||||
|
* @param formatString Date format string defined using ICU date formatting
|
||||||
|
* symbols. Usually, you internationalize the format string and
|
||||||
|
* get it translated before you pass it to
|
||||||
|
* FormatMillisecondsIntoDateString().
|
||||||
|
* @return String containing the specified date with the specified date
|
||||||
|
* format.
|
||||||
|
*
|
||||||
|
* @sa http://en.wikipedia.org/wiki/Unix_time
|
||||||
|
* @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
|
||||||
|
*/
|
||||||
|
std::wstring FormatMillisecondsIntoDateStringGMT(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the specified floating-point number as a string, with the number
|
* Returns the specified floating-point number as a string, with the number
|
||||||
|
Loading…
Reference in New Issue
Block a user