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 (isNumber) pollHeader += ` step=${step}`;
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 += ']';
output += `${pollHeader}\n`;
@ -186,7 +189,7 @@ export default Ember.Controller.extend({
pollMax: null,
pollStep: 1,
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"),
});
},

View File

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