fix(i18n): timestamp stripping year part

Use locale-neutral `getDayMonth()` plus the time part as there's no way
to programatically check for date parts separator.

Fixes #10615
This commit is contained in:
Lukáš Tinkl 2023-08-29 10:50:20 +02:00 committed by Lukáš Tinkl
parent ae5381a29f
commit a210189137
1 changed files with 5 additions and 8 deletions

View File

@ -431,17 +431,14 @@ QtObject {
return qsTr("%1 %2").arg(loc.standaloneDayName(value.getDay(), Locale.ShortFormat)).arg(value.toLocaleTimeString(loc, formatString))
}
// otherwise
var fullFormatString = d.fixupTimeFormatString(loc.dateTimeFormat(Locale.ShortFormat))
// within this year
if (now.getFullYear() === value.getFullYear()) {
// strip year part, if current year -> "31 December 09:41"
// It remove preceding dot or space
fullFormatString = fullFormatString.replace(/([.\s])?\b(y+)\b/g, "")
} else if (!fullFormatString.includes("yyyy")) {
fullFormatString = fullFormatString.replace("yy", "yyyy") // different year -> "31 December 2022 09:41"
// strip year part, if current year -> "31 Dec 09:41"
return getDayMonth(value) + " " + formatTime(value, Locale.ShortFormat)
}
return value.toLocaleString(loc, fullFormatString)
// otherwise
return formatDateTime(value, Locale.ShortFormat)
}
function getTimeDifference(d1, d2) {