Description
const datetime = new SimpleDateTime();
const duration = new SimpleDuration(datetime.getNumericValue());
const display = duration.getDisplayValue();
ss.info(display);
// Информация: 19297 days 41 minutes 2 seconds
Workaround
Использовать скрипт:
const datetime = new SimpleDateTime();
ss.info(localizeDuration(datetime.getNumericValue()));
function localizeDuration(durationSeconds) {
const duration = new SimpleDuration(durationSeconds);
const displayValue = duration.getDisplayValue();
if (ss.getUser().language_id.language === 'en') {
return displayValue;
}
const dict = {
"1": ["день", "дня", "дней"],
"4": ["час", "часа", "часов"],
"7": ["минута", "минуты", "минут"],
"10": ["секунда", "секунды", "секунд"]
};
const match = displayValue.match(/(\d+ day(s)?)?(\s)?(\d+ hour(s)?)?(\s)?(\d+ minute(s)?)?(\s)?(\d+ second(s)?)?/);
let result = [];
["1", "4", "7", "10"].forEach(key => {
if (!match[key]) return false;
const number = match[key].match(/\d+/g);
result.push(`${number} ${getNoun(number[0], ...dict[key])}`);
})
return result.join(' ');
}
function getNoun(number, one, two, five) {
let n = Math.abs(number);
n %= 100;
if (n >= 5 && n <= 20) {
return five;
}
n %= 10;
if (n === 1) {
return one;
}
if (n >= 2 && n <= 4) {
return two;
}
return five;
}