FIX: properly handle invalid auto close date for polls

This commit is contained in:
Régis Hanol
2018-06-12 15:31:09 +02:00
parent d8063d09d5
commit 5d445fb810
2 changed files with 12 additions and 7 deletions

View File

@ -118,7 +118,10 @@ export default Ember.Controller.extend({
if (pollMax) pollHeader += ` max=${pollMax}`; if (pollMax) pollHeader += ` max=${pollMax}`;
if (isNumber) pollHeader += ` step=${step}`; if (isNumber) pollHeader += ` step=${step}`;
if (publicPoll) pollHeader += ` public=true`; if (publicPoll) pollHeader += ` public=true`;
if (autoClose) pollHeader += ` close=${moment(date + " " + time, "YYYY-MM-DD HH:mm").toISOString()}`; if (autoClose) {
let closeDate = moment(date + " " + time, "YYYY-MM-DD HH:mm").toISOString();
if (closeDate) pollHeader += ` close=${closeDate}`;
}
pollHeader += ']'; pollHeader += ']';
output += `${pollHeader}\n`; output += `${pollHeader}\n`;
@ -186,7 +189,7 @@ export default Ember.Controller.extend({
pollMax: null, pollMax: null,
pollStep: 1, pollStep: 1,
autoClose: false, autoClose: false,
date: moment().add(1, "day").format("YYYY-DD-MM"), date: moment().add(1, "day").format("YYYY-MM-DD"),
time: moment().add(1, "hour").format("HH:mm"), time: moment().add(1, "hour").format("HH:mm"),
}); });
}, },

View File

@ -354,12 +354,14 @@ createWidget('discourse-poll-info', {
if (poll.close) { if (poll.close) {
const closeDate = moment.utc(poll.close); const closeDate = moment.utc(poll.close);
const title = closeDate.format("LLL"); if (closeDate.isValid()) {
const timeLeft = moment().to(closeDate.local(), true); const title = closeDate.format("LLL");
const timeLeft = moment().to(closeDate.local(), true);
result.push(new RawHtml({ result.push(new RawHtml({
html: `<span class="info-text" title="${title}">${I18n.t("poll.automatic_close.closes_in", { timeLeft })}</span>` html: `<span class="info-text" title="${title}">${I18n.t("poll.automatic_close.closes_in", { timeLeft })}</span>`
})); }));
}
} }
} }