UX: remove "at" word from relative dates in local dates

Previously we would render "Today at 2:42 PM"
Now we render "Today 2:42 PM"

This also introduces new strings so it can be properly translated

Finally it introduces tests so we can make sure this keeps working
This commit is contained in:
Sam 2018-10-31 11:55:31 +11:00
parent d6f89a85ef
commit df62b48d51
3 changed files with 52 additions and 1 deletions

View File

@ -56,6 +56,26 @@
var displayTimezone = moment.tz.guess();
var relativeTime = relativeTime.tz(displayTimezone);
var d = function(key) {
var translated = I18n.t("discourse_local_dates.relative_dates." + key, {
time: "LT"
});
translated = translated
.split("LT")
.map(function(w) {
return "[" + w + "]";
})
.join("LT");
return translated;
};
var relativeFormat = {
sameDay: d("today"),
nextDay: d("tomorrow"),
lastDay: d("yesterday"),
sameElse: "L"
};
if (
options.format !== "YYYY-MM-DD HH:mm:ss" &&
relativeTime.isBetween(
@ -63,7 +83,7 @@
moment().add(2, "day")
)
) {
relativeTime = relativeTime.calendar();
relativeTime = relativeTime.calendar(null, relativeFormat);
} else {
relativeTime = relativeTime.format(options.format);
}

View File

@ -1,6 +1,10 @@
en:
js:
discourse_local_dates:
relative_dates:
today: Today %{time}
tomorrow: Tomorrow %{time}
yesterday: Yesterday %{time}
title: Insert date
create:
modal_title: Insert date

View File

@ -6,9 +6,36 @@ acceptance("Local Dates", {
settings: { discourse_local_dates_enabled: true },
beforeEach() {
clearPopupMenuOptionsCallback();
},
afterEach() {
sinon.restore();
}
});
test("at removal", assert => {
let now = moment("2018-06-20").valueOf();
let timezone = moment.tz.guess();
sinon.useFakeTimers(now);
let html = `<span data-timezones="${timezone}" data-timezone="${timezone}" class="discourse-local-date past cooked-date" data-date="DATE" data-format="L LTS" data-time="14:42:26"></span>`;
let yesterday = $(html.replace("DATE", "2018-06-19"));
yesterday.applyLocalDates();
assert.equal(yesterday.text(), "Yesterday 2:42 PM");
let today = $(html.replace("DATE", "2018-06-20"));
today.applyLocalDates();
assert.equal(today.text(), "Today 2:42 PM");
let tomorrow = $(html.replace("DATE", "2018-06-21"));
tomorrow.applyLocalDates();
assert.equal(tomorrow.text(), "Tomorrow 2:42 PM");
});
test("local dates bbcode", async assert => {
await visit("/");
await click("#create-topic");