mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 09:22:47 +08:00
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:
parent
d6f89a85ef
commit
df62b48d51
|
@ -56,6 +56,26 @@
|
||||||
var displayTimezone = moment.tz.guess();
|
var displayTimezone = moment.tz.guess();
|
||||||
var relativeTime = relativeTime.tz(displayTimezone);
|
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 (
|
if (
|
||||||
options.format !== "YYYY-MM-DD HH:mm:ss" &&
|
options.format !== "YYYY-MM-DD HH:mm:ss" &&
|
||||||
relativeTime.isBetween(
|
relativeTime.isBetween(
|
||||||
|
@ -63,7 +83,7 @@
|
||||||
moment().add(2, "day")
|
moment().add(2, "day")
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
relativeTime = relativeTime.calendar();
|
relativeTime = relativeTime.calendar(null, relativeFormat);
|
||||||
} else {
|
} else {
|
||||||
relativeTime = relativeTime.format(options.format);
|
relativeTime = relativeTime.format(options.format);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
en:
|
en:
|
||||||
js:
|
js:
|
||||||
discourse_local_dates:
|
discourse_local_dates:
|
||||||
|
relative_dates:
|
||||||
|
today: Today %{time}
|
||||||
|
tomorrow: Tomorrow %{time}
|
||||||
|
yesterday: Yesterday %{time}
|
||||||
title: Insert date
|
title: Insert date
|
||||||
create:
|
create:
|
||||||
modal_title: Insert date
|
modal_title: Insert date
|
||||||
|
|
|
@ -6,9 +6,36 @@ acceptance("Local Dates", {
|
||||||
settings: { discourse_local_dates_enabled: true },
|
settings: { discourse_local_dates_enabled: true },
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
clearPopupMenuOptionsCallback();
|
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 => {
|
test("local dates bbcode", async assert => {
|
||||||
await visit("/");
|
await visit("/");
|
||||||
await click("#create-topic");
|
await click("#create-topic");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user