mirror of https://github.com/zulip/zulip.git
timerender: Extract new variant of get_full_datetime.
Separating these concepts allows us to provide a much nicer format for contexts where ultra-specific clarification is not a priority. This new variant is currently only used in the scheduled messages UI.
This commit is contained in:
parent
341f3a1ce2
commit
6fe02e933a
|
@ -189,6 +189,8 @@ function valid_to(expires_in) {
|
|||
if (!time_valid) {
|
||||
return $t({defaultMessage: "Never expires"});
|
||||
}
|
||||
|
||||
// The below is a duplicate of timerender.get_full_datetime, with a different base string.
|
||||
const valid_to = add(new Date(), {minutes: time_valid});
|
||||
const date = timerender.get_localized_date_or_time_for_format(valid_to, "dayofyear_year");
|
||||
const time = timerender.get_localized_date_or_time_for_format(valid_to, "time");
|
||||
|
|
|
@ -360,7 +360,7 @@ function format_conversation(conversation_data) {
|
|||
const last_msg = message_store.get(conversation_data.last_msg_id);
|
||||
const time = new Date(last_msg.timestamp * 1000);
|
||||
const type = last_msg.type;
|
||||
context.full_last_msg_date_time = timerender.get_full_datetime(time);
|
||||
context.full_last_msg_date_time = timerender.get_full_datetime_clarification(time);
|
||||
context.conversation_key = get_key_from_message(last_msg);
|
||||
context.unread_count = message_to_conversation_unread_count(last_msg);
|
||||
context.last_msg_time = timerender.relative_time_string_from_date(time);
|
||||
|
|
|
@ -446,6 +446,18 @@ export function absolute_time(timestamp: number, today = new Date()): string {
|
|||
|
||||
// Pass time_format="time" to not include seconds in the time format.
|
||||
export function get_full_datetime(time: Date, time_format: TimeFormat = "time_sec"): string {
|
||||
const date_string = get_localized_date_or_time_for_format(time, "dayofyear_year");
|
||||
const time_string = get_localized_date_or_time_for_format(time, time_format);
|
||||
return $t({defaultMessage: "{date} at {time}"}, {date: date_string, time: time_string});
|
||||
}
|
||||
|
||||
// Preferred variant for displaying a full datetime to users in
|
||||
// contexts like tooltips, where the time was already displayed to the
|
||||
// user in a less precise format.
|
||||
export function get_full_datetime_clarification(
|
||||
time: Date,
|
||||
time_format: TimeFormat = "time_sec",
|
||||
): string {
|
||||
const locale = get_user_locale();
|
||||
const date_string = time.toLocaleDateString(locale);
|
||||
let time_string = get_localized_date_or_time_for_format(time, time_format);
|
||||
|
|
|
@ -371,7 +371,7 @@ export function initialize() {
|
|||
return false;
|
||||
}
|
||||
const time = new Date(message.timestamp * 1000);
|
||||
instance.setContent(timerender.get_full_datetime(time));
|
||||
instance.setContent(timerender.get_full_datetime_clarification(time));
|
||||
return true;
|
||||
},
|
||||
onHidden(instance) {
|
||||
|
|
|
@ -138,7 +138,7 @@ mock_esm("../src/stream_list", {
|
|||
});
|
||||
mock_esm("../src/timerender", {
|
||||
relative_time_string_from_date: () => "Just now",
|
||||
get_full_datetime: () => "date at time",
|
||||
get_full_datetime_clarification: () => "date at time",
|
||||
});
|
||||
mock_esm("../src/sub_store", {
|
||||
get(stream) {
|
||||
|
|
|
@ -288,7 +288,7 @@ run_test("format_time_modern_different_timezones", () => {
|
|||
|
||||
process.env.TZ = "America/Juneau";
|
||||
let expected = "translated: 5/16/2017 at 11:12:53 PM AKDT (UTC-08:00)";
|
||||
assert.equal(timerender.get_full_datetime(yesterday), expected);
|
||||
assert.equal(timerender.get_full_datetime_clarification(yesterday), expected);
|
||||
assert.equal(timerender.format_time_modern(yesterday, today), "Tuesday");
|
||||
process.env.TZ = utc_tz;
|
||||
|
||||
|
@ -299,7 +299,7 @@ run_test("format_time_modern_different_timezones", () => {
|
|||
|
||||
process.env.TZ = "Asia/Brunei";
|
||||
expected = "translated: 5/17/2017 at 5:12:53 AM (UTC+08:00)";
|
||||
assert.equal(timerender.get_full_datetime(yesterday), expected);
|
||||
assert.equal(timerender.get_full_datetime_clarification(yesterday), expected);
|
||||
assert.equal(timerender.format_time_modern(yesterday, today), "translated: Yesterday");
|
||||
process.env.TZ = utc_tz;
|
||||
|
||||
|
@ -310,7 +310,7 @@ run_test("format_time_modern_different_timezones", () => {
|
|||
|
||||
process.env.TZ = "America/Juneau";
|
||||
expected = "translated: 5/11/2017 at 11:12:53 PM AKDT (UTC-08:00)";
|
||||
assert.equal(timerender.get_full_datetime(yesterday), expected);
|
||||
assert.equal(timerender.get_full_datetime_clarification(yesterday), expected);
|
||||
assert.equal(timerender.format_time_modern(yesterday, today), "May 11");
|
||||
process.env.TZ = utc_tz;
|
||||
});
|
||||
|
@ -446,14 +446,20 @@ run_test("get_full_datetime", () => {
|
|||
const time = date_2017_PM;
|
||||
|
||||
let expected = "translated: 5/18/2017 at 9:12:53 PM UTC";
|
||||
assert.equal(timerender.get_full_datetime_clarification(time), expected);
|
||||
expected = "translated: May 18, 2017 at 9:12:53 PM";
|
||||
assert.equal(timerender.get_full_datetime(time), expected);
|
||||
|
||||
expected = "translated: 5/18/2017 at 9:12 PM UTC";
|
||||
assert.equal(timerender.get_full_datetime_clarification(time, "time"), expected);
|
||||
expected = "translated: May 18, 2017 at 9:12 PM";
|
||||
assert.equal(timerender.get_full_datetime(time, "time"), expected);
|
||||
|
||||
// test 24 hour time setting.
|
||||
user_settings.twenty_four_hour_time = true;
|
||||
expected = "translated: 5/18/2017 at 21:12:53 UTC";
|
||||
assert.equal(timerender.get_full_datetime_clarification(time), expected);
|
||||
expected = "translated: May 18, 2017 at 21:12:53";
|
||||
assert.equal(timerender.get_full_datetime(time), expected);
|
||||
|
||||
user_settings.twenty_four_hour_time = false;
|
||||
|
@ -462,6 +468,8 @@ run_test("get_full_datetime", () => {
|
|||
const previous_env_tz = process.env.TZ;
|
||||
process.env.TZ = "Asia/Kolkata";
|
||||
expected = "translated: 5/19/2017 at 2:42:53 AM (UTC+05:30)";
|
||||
assert.equal(timerender.get_full_datetime_clarification(time), expected);
|
||||
expected = "translated: May 19, 2017 at 2:42:53 AM";
|
||||
assert.equal(timerender.get_full_datetime(time), expected);
|
||||
process.env.TZ = previous_env_tz;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue