2020-08-01 03:43:15 +02:00
|
|
|
|
"use strict";
|
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const {add} = require("date-fns");
|
2021-02-05 22:46:37 +01:00
|
|
|
|
const MockDate = require("mockdate");
|
2020-07-28 00:26:58 +02:00
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
|
const {$t} = require("./lib/i18n");
|
|
|
|
|
const {zrequire} = require("./lib/namespace");
|
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
|
const $ = require("./lib/zjquery");
|
|
|
|
|
const {user_settings} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
|
2021-07-28 16:00:58 +02:00
|
|
|
|
user_settings.twenty_four_hour_time = true;
|
2020-07-24 06:02:07 +02:00
|
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
|
const timerender = zrequire("timerender");
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2022-02-09 14:56:52 +01:00
|
|
|
|
function get_date(time_ISO, DOW) {
|
|
|
|
|
const time = new Date(time_ISO);
|
|
|
|
|
// DOW helps the test reader to know the DOW of the current date being tested.
|
|
|
|
|
assert.equal(new Intl.DateTimeFormat("en-US", {weekday: "long"}).format(time), DOW);
|
|
|
|
|
return time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const date_2017 = get_date("2017-05-18T07:12:53.000Z", "Thursday");
|
|
|
|
|
|
|
|
|
|
// Check there is no UTC offset.
|
|
|
|
|
assert.equal(timerender.get_tz_with_UTC_offset(date_2017.getTime()), "UTC");
|
|
|
|
|
|
|
|
|
|
const date_2017_PM = get_date("2017-05-18T21:12:53.000Z", "Thursday");
|
|
|
|
|
|
|
|
|
|
const date_2019 = get_date("2019-04-12T17:52:53.000Z", "Friday");
|
|
|
|
|
|
|
|
|
|
const date_2021 = get_date("2021-01-27T01:53:08.000Z", "Wednesday");
|
|
|
|
|
|
|
|
|
|
const date_2025 = get_date("2025-03-03T12:10:00.000Z", "Monday");
|
|
|
|
|
|
2023-01-08 18:08:49 +01:00
|
|
|
|
run_test("get_localized_date_or_time_for_format returns default date with incorrect locale", () => {
|
|
|
|
|
const date = date_2019;
|
|
|
|
|
const expectedDate = "Friday, April 12, 2019";
|
|
|
|
|
|
|
|
|
|
user_settings.default_language = "invalidLanguageCode";
|
|
|
|
|
const actualDate = timerender.get_localized_date_or_time_for_format(
|
|
|
|
|
date,
|
|
|
|
|
"weekday_dayofyear_year",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.equal(actualDate, expectedDate);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
run_test("get_localized_date_or_time_for_format returns correct format", () => {
|
|
|
|
|
const date = date_2021;
|
|
|
|
|
const formats = [
|
|
|
|
|
{
|
|
|
|
|
format: "time",
|
|
|
|
|
expected: {
|
2023-03-16 19:40:55 +01:00
|
|
|
|
date: "1:53 AM",
|
2023-01-08 18:08:49 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: "time_sec",
|
|
|
|
|
expected: {
|
2023-03-16 19:40:55 +01:00
|
|
|
|
date: "1:53:08 AM",
|
2023-01-08 18:08:49 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: "weekday",
|
|
|
|
|
expected: {
|
|
|
|
|
date: "Wednesday",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: "dayofyear",
|
|
|
|
|
expected: {
|
|
|
|
|
date: "Jan 27",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: "dayofyear_time",
|
|
|
|
|
expected: {
|
2023-03-16 19:40:55 +01:00
|
|
|
|
date: "Jan 27, 1:53 AM",
|
2023-01-08 18:08:49 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: "dayofyear_year",
|
|
|
|
|
expected: {
|
|
|
|
|
date: "Jan 27, 2021",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: "dayofyear_year_time",
|
|
|
|
|
expected: {
|
2023-03-16 19:40:55 +01:00
|
|
|
|
date: "Jan 27, 2021, 1:53 AM",
|
2023-01-08 18:08:49 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: "weekday_dayofyear_year",
|
|
|
|
|
expected: {
|
|
|
|
|
date: "Wednesday, January 27, 2021",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: "weekday_dayofyear_year_time",
|
|
|
|
|
expected: {
|
2023-03-16 19:40:55 +01:00
|
|
|
|
date: "Wed, Jan 27, 2021, 1:53 AM",
|
2023-01-08 18:08:49 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (const format of formats) {
|
|
|
|
|
const actualDate = timerender.get_localized_date_or_time_for_format(date, format.format);
|
|
|
|
|
assert.equal(actualDate, format.expected.date);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
run_test("get_localized_date_or_time_for_format returns correct localized date", () => {
|
|
|
|
|
const date = add(date_2019, {years: -1});
|
|
|
|
|
const languages = [
|
|
|
|
|
{
|
|
|
|
|
language: "en",
|
|
|
|
|
expected: {
|
|
|
|
|
date: "Thursday, April 12, 2018",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
language: "ru",
|
|
|
|
|
expected: {
|
2023-03-16 19:40:55 +01:00
|
|
|
|
date: "четверг, 12 апреля 2018 г.",
|
2023-01-08 18:08:49 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
language: "fr",
|
|
|
|
|
expected: {
|
|
|
|
|
date: "jeudi 12 avril 2018",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
language: "de",
|
|
|
|
|
expected: {
|
|
|
|
|
date: "Donnerstag, 12. April 2018",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
language: "su",
|
|
|
|
|
expected: {
|
|
|
|
|
date: "Kemis, 12 April 2018",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
language: "it",
|
|
|
|
|
expected: {
|
|
|
|
|
date: "giovedì 12 aprile 2018",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (const language of languages) {
|
|
|
|
|
user_settings.default_language = language.language;
|
|
|
|
|
const actualDate = timerender.get_localized_date_or_time_for_format(
|
|
|
|
|
date,
|
|
|
|
|
"weekday_dayofyear_year",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(actualDate, language.expected.date);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-07-02 19:13:46 +02:00
|
|
|
|
run_test("get_tz_with_UTC_offset", () => {
|
2022-02-09 14:56:52 +01:00
|
|
|
|
let time = date_2019;
|
2021-07-02 19:13:46 +02:00
|
|
|
|
|
2022-02-09 14:56:52 +01:00
|
|
|
|
assert.equal(timerender.get_tz_with_UTC_offset(time), "UTC");
|
2021-07-02 19:13:46 +02:00
|
|
|
|
const previous_env_tz = process.env.TZ;
|
|
|
|
|
|
|
|
|
|
// Test the GMT[+-]x:y logic.
|
|
|
|
|
process.env.TZ = "Asia/Kolkata";
|
|
|
|
|
assert.equal(timerender.get_tz_with_UTC_offset(time), "(UTC+05:30)");
|
|
|
|
|
|
|
|
|
|
process.env.TZ = "America/Los_Angeles";
|
|
|
|
|
assert.equal(timerender.get_tz_with_UTC_offset(time), "PDT (UTC-07:00)");
|
|
|
|
|
|
2022-02-09 14:56:52 +01:00
|
|
|
|
time = date_2025;
|
|
|
|
|
|
2021-07-02 19:13:46 +02:00
|
|
|
|
assert.equal(timerender.get_tz_with_UTC_offset(time), "PST (UTC-08:00)");
|
|
|
|
|
|
|
|
|
|
process.env.TZ = previous_env_tz;
|
|
|
|
|
});
|
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("render_now_returns_today", () => {
|
2022-02-09 14:56:52 +01:00
|
|
|
|
const today = date_2019;
|
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = {
|
2021-04-13 06:51:54 +02:00
|
|
|
|
time_str: $t({defaultMessage: "Today"}),
|
2023-01-08 18:08:49 +01:00
|
|
|
|
formal_time_str: "Friday, April 12, 2019",
|
2017-05-18 21:18:11 +02:00
|
|
|
|
needs_update: true,
|
|
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const actual = timerender.render_now(today, today);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual.time_str, expected.time_str);
|
|
|
|
|
assert.equal(actual.formal_time_str, expected.formal_time_str);
|
|
|
|
|
assert.equal(actual.needs_update, expected.needs_update);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("render_now_returns_yesterday", () => {
|
2022-02-09 14:56:52 +01:00
|
|
|
|
const today = date_2019;
|
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const yesterday = add(today, {days: -1});
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = {
|
2021-04-13 06:51:54 +02:00
|
|
|
|
time_str: $t({defaultMessage: "Yesterday"}),
|
2023-01-08 18:08:49 +01:00
|
|
|
|
formal_time_str: "Thursday, April 11, 2019",
|
2017-05-18 21:18:11 +02:00
|
|
|
|
needs_update: true,
|
|
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const actual = timerender.render_now(yesterday, today);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual.time_str, expected.time_str);
|
|
|
|
|
assert.equal(actual.formal_time_str, expected.formal_time_str);
|
|
|
|
|
assert.equal(actual.needs_update, expected.needs_update);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("render_now_returns_year", () => {
|
2022-02-09 14:56:52 +01:00
|
|
|
|
const today = date_2019;
|
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const year_ago = add(today, {years: -1});
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = {
|
2023-01-08 18:08:49 +01:00
|
|
|
|
time_str: "Apr 12, 2018",
|
|
|
|
|
formal_time_str: "Thursday, April 12, 2018",
|
2017-05-18 21:18:11 +02:00
|
|
|
|
needs_update: false,
|
|
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const actual = timerender.render_now(year_ago, today);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual.time_str, expected.time_str);
|
|
|
|
|
assert.equal(actual.formal_time_str, expected.formal_time_str);
|
|
|
|
|
assert.equal(actual.needs_update, expected.needs_update);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("render_now_returns_month_and_day", () => {
|
2022-02-09 14:56:52 +01:00
|
|
|
|
const today = date_2019;
|
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const three_months_ago = add(today, {months: -3});
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = {
|
2023-01-08 18:08:49 +01:00
|
|
|
|
time_str: "Jan 12",
|
|
|
|
|
formal_time_str: "Saturday, January 12, 2019",
|
2017-05-18 21:18:11 +02:00
|
|
|
|
needs_update: false,
|
|
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const actual = timerender.render_now(three_months_ago, today);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual.time_str, expected.time_str);
|
|
|
|
|
assert.equal(actual.formal_time_str, expected.formal_time_str);
|
|
|
|
|
assert.equal(actual.needs_update, expected.needs_update);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
recent_topics: Standardize format of last message time.
We follow how other apps present older messages, e.g. Gmail,
Facebook Messenger, etc. display it.
Specifically, the logic we use is:
If the time is <24hr ago, show an absolute time, like "21:30" (or "9:30pm").
Otherwise, show what day it was, and not a time
If the day was yesterday, say "Yesterday".
Otherwise, if it was <7 days ago, say the day of week, like "Friday".
Otherwise, if it was <1 year ago, say the month and day, like "Sep 6".
Otherwise, say the year, month, and day, like "Sep 9, 2020".
With some tweaks from Tim Abbott to better handle the future case.
Fixes #19775
2022-02-09 14:59:51 +01:00
|
|
|
|
run_test("format_time_modern", () => {
|
|
|
|
|
const today = date_2021;
|
|
|
|
|
|
|
|
|
|
const few_minutes_in_future = add(today, {minutes: 30});
|
|
|
|
|
const weeks_in_future = add(today, {days: 20});
|
|
|
|
|
const less_than_24_hours_ago = add(today, {hours: -23});
|
|
|
|
|
const twenty_four_hours_ago = add(today, {hours: -24});
|
|
|
|
|
const more_than_24_hours_ago = add(today, {hours: -25});
|
|
|
|
|
const less_than_a_week_ago = add(today, {days: -6});
|
|
|
|
|
const one_week_ago = add(today, {days: -7});
|
|
|
|
|
const less_than_6_months_ago = add(today, {months: -3});
|
|
|
|
|
const more_than_6_months_ago = add(today, {months: -9});
|
|
|
|
|
const previous_year_but_less_than_6_months = add(today, {months: -1});
|
|
|
|
|
|
2023-01-08 18:08:49 +01:00
|
|
|
|
assert.equal(timerender.format_time_modern(few_minutes_in_future, today), "Jan 27, 2021");
|
|
|
|
|
assert.equal(timerender.format_time_modern(weeks_in_future, today), "Feb 16, 2021");
|
2023-03-16 19:40:55 +01:00
|
|
|
|
assert.equal(timerender.format_time_modern(less_than_24_hours_ago, today), "2:53 AM");
|
recent_topics: Standardize format of last message time.
We follow how other apps present older messages, e.g. Gmail,
Facebook Messenger, etc. display it.
Specifically, the logic we use is:
If the time is <24hr ago, show an absolute time, like "21:30" (or "9:30pm").
Otherwise, show what day it was, and not a time
If the day was yesterday, say "Yesterday".
Otherwise, if it was <7 days ago, say the day of week, like "Friday".
Otherwise, if it was <1 year ago, say the month and day, like "Sep 6".
Otherwise, say the year, month, and day, like "Sep 9, 2020".
With some tweaks from Tim Abbott to better handle the future case.
Fixes #19775
2022-02-09 14:59:51 +01:00
|
|
|
|
assert.equal(
|
|
|
|
|
timerender.format_time_modern(twenty_four_hours_ago, today),
|
|
|
|
|
"translated: Yesterday",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(
|
|
|
|
|
timerender.format_time_modern(more_than_24_hours_ago, today),
|
|
|
|
|
"translated: Yesterday",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(timerender.format_time_modern(less_than_a_week_ago, today), "Thursday");
|
2023-01-08 18:08:49 +01:00
|
|
|
|
assert.equal(timerender.format_time_modern(one_week_ago, today), "Jan 20");
|
recent_topics: Standardize format of last message time.
We follow how other apps present older messages, e.g. Gmail,
Facebook Messenger, etc. display it.
Specifically, the logic we use is:
If the time is <24hr ago, show an absolute time, like "21:30" (or "9:30pm").
Otherwise, show what day it was, and not a time
If the day was yesterday, say "Yesterday".
Otherwise, if it was <7 days ago, say the day of week, like "Friday".
Otherwise, if it was <1 year ago, say the month and day, like "Sep 6".
Otherwise, say the year, month, and day, like "Sep 9, 2020".
With some tweaks from Tim Abbott to better handle the future case.
Fixes #19775
2022-02-09 14:59:51 +01:00
|
|
|
|
assert.equal(
|
|
|
|
|
timerender.format_time_modern(previous_year_but_less_than_6_months, today),
|
2023-01-08 18:08:49 +01:00
|
|
|
|
"Dec 27",
|
recent_topics: Standardize format of last message time.
We follow how other apps present older messages, e.g. Gmail,
Facebook Messenger, etc. display it.
Specifically, the logic we use is:
If the time is <24hr ago, show an absolute time, like "21:30" (or "9:30pm").
Otherwise, show what day it was, and not a time
If the day was yesterday, say "Yesterday".
Otherwise, if it was <7 days ago, say the day of week, like "Friday".
Otherwise, if it was <1 year ago, say the month and day, like "Sep 6".
Otherwise, say the year, month, and day, like "Sep 9, 2020".
With some tweaks from Tim Abbott to better handle the future case.
Fixes #19775
2022-02-09 14:59:51 +01:00
|
|
|
|
);
|
2023-01-08 18:08:49 +01:00
|
|
|
|
assert.equal(timerender.format_time_modern(less_than_6_months_ago, today), "Oct 27");
|
|
|
|
|
assert.equal(timerender.format_time_modern(more_than_6_months_ago, today), "Apr 27, 2020");
|
recent_topics: Standardize format of last message time.
We follow how other apps present older messages, e.g. Gmail,
Facebook Messenger, etc. display it.
Specifically, the logic we use is:
If the time is <24hr ago, show an absolute time, like "21:30" (or "9:30pm").
Otherwise, show what day it was, and not a time
If the day was yesterday, say "Yesterday".
Otherwise, if it was <7 days ago, say the day of week, like "Friday".
Otherwise, if it was <1 year ago, say the month and day, like "Sep 6".
Otherwise, say the year, month, and day, like "Sep 9, 2020".
With some tweaks from Tim Abbott to better handle the future case.
Fixes #19775
2022-02-09 14:59:51 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
run_test("format_time_modern_different_timezones", () => {
|
|
|
|
|
const utc_tz = process.env.TZ;
|
|
|
|
|
|
|
|
|
|
// Day is yesterday in UTC+0 but is 2 days ago in local timezone hence DOW is returned.
|
|
|
|
|
let today = date_2017_PM;
|
|
|
|
|
let yesterday = add(date_2017, {days: -1});
|
|
|
|
|
assert.equal(timerender.format_time_modern(yesterday, today), "translated: Yesterday");
|
|
|
|
|
|
|
|
|
|
process.env.TZ = "America/Juneau";
|
2023-03-16 19:40:55 +01:00
|
|
|
|
let expected = "translated: 5/16/2017 at 11:12:53 PM AKDT (UTC-08:00)";
|
2023-05-01 07:02:10 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime_clarification(yesterday), expected);
|
recent_topics: Standardize format of last message time.
We follow how other apps present older messages, e.g. Gmail,
Facebook Messenger, etc. display it.
Specifically, the logic we use is:
If the time is <24hr ago, show an absolute time, like "21:30" (or "9:30pm").
Otherwise, show what day it was, and not a time
If the day was yesterday, say "Yesterday".
Otherwise, if it was <7 days ago, say the day of week, like "Friday".
Otherwise, if it was <1 year ago, say the month and day, like "Sep 6".
Otherwise, say the year, month, and day, like "Sep 9, 2020".
With some tweaks from Tim Abbott to better handle the future case.
Fixes #19775
2022-02-09 14:59:51 +01:00
|
|
|
|
assert.equal(timerender.format_time_modern(yesterday, today), "Tuesday");
|
|
|
|
|
process.env.TZ = utc_tz;
|
|
|
|
|
|
|
|
|
|
// Day is 2 days ago in UTC+0 but is yesterday in local timezone.
|
|
|
|
|
today = date_2017;
|
|
|
|
|
yesterday = add(date_2017_PM, {days: -2});
|
|
|
|
|
assert.equal(timerender.format_time_modern(yesterday, today), "Tuesday");
|
|
|
|
|
|
|
|
|
|
process.env.TZ = "Asia/Brunei";
|
2023-03-16 19:40:55 +01:00
|
|
|
|
expected = "translated: 5/17/2017 at 5:12:53 AM (UTC+08:00)";
|
2023-05-01 07:02:10 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime_clarification(yesterday), expected);
|
recent_topics: Standardize format of last message time.
We follow how other apps present older messages, e.g. Gmail,
Facebook Messenger, etc. display it.
Specifically, the logic we use is:
If the time is <24hr ago, show an absolute time, like "21:30" (or "9:30pm").
Otherwise, show what day it was, and not a time
If the day was yesterday, say "Yesterday".
Otherwise, if it was <7 days ago, say the day of week, like "Friday".
Otherwise, if it was <1 year ago, say the month and day, like "Sep 6".
Otherwise, say the year, month, and day, like "Sep 9, 2020".
With some tweaks from Tim Abbott to better handle the future case.
Fixes #19775
2022-02-09 14:59:51 +01:00
|
|
|
|
assert.equal(timerender.format_time_modern(yesterday, today), "translated: Yesterday");
|
|
|
|
|
process.env.TZ = utc_tz;
|
|
|
|
|
|
|
|
|
|
// Day is 6 days ago in UTC+0 but a week ago in local timezone hence difference in returned strings.
|
|
|
|
|
today = date_2017_PM;
|
|
|
|
|
yesterday = add(date_2017, {days: -6});
|
|
|
|
|
assert.equal(timerender.format_time_modern(yesterday, today), "Friday");
|
|
|
|
|
|
|
|
|
|
process.env.TZ = "America/Juneau";
|
2023-03-16 19:40:55 +01:00
|
|
|
|
expected = "translated: 5/11/2017 at 11:12:53 PM AKDT (UTC-08:00)";
|
2023-05-01 07:02:10 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime_clarification(yesterday), expected);
|
2023-01-08 18:08:49 +01:00
|
|
|
|
assert.equal(timerender.format_time_modern(yesterday, today), "May 11");
|
recent_topics: Standardize format of last message time.
We follow how other apps present older messages, e.g. Gmail,
Facebook Messenger, etc. display it.
Specifically, the logic we use is:
If the time is <24hr ago, show an absolute time, like "21:30" (or "9:30pm").
Otherwise, show what day it was, and not a time
If the day was yesterday, say "Yesterday".
Otherwise, if it was <7 days ago, say the day of week, like "Friday".
Otherwise, if it was <1 year ago, say the month and day, like "Sep 6".
Otherwise, say the year, month, and day, like "Sep 9, 2020".
With some tweaks from Tim Abbott to better handle the future case.
Fixes #19775
2022-02-09 14:59:51 +01:00
|
|
|
|
process.env.TZ = utc_tz;
|
|
|
|
|
});
|
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("render_now_returns_year_with_year_boundary", () => {
|
2022-02-09 14:56:52 +01:00
|
|
|
|
const today = date_2019;
|
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const six_months_ago = add(today, {months: -6});
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = {
|
2023-01-08 18:08:49 +01:00
|
|
|
|
time_str: "Oct 12, 2018",
|
|
|
|
|
formal_time_str: "Friday, October 12, 2018",
|
2017-05-24 02:20:06 +02:00
|
|
|
|
needs_update: false,
|
|
|
|
|
};
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const actual = timerender.render_now(six_months_ago, today);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual.time_str, expected.time_str);
|
|
|
|
|
assert.equal(actual.formal_time_str, expected.formal_time_str);
|
|
|
|
|
assert.equal(actual.needs_update, expected.needs_update);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-05-24 02:20:06 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("render_date_renders_time_html", () => {
|
2021-03-14 15:57:08 +01:00
|
|
|
|
timerender.clear_for_testing();
|
|
|
|
|
|
2022-02-09 14:56:52 +01:00
|
|
|
|
const today = date_2019;
|
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const message_time = today;
|
2021-04-13 06:51:54 +02:00
|
|
|
|
const expected_html = $t({defaultMessage: "Today"});
|
2017-06-02 16:38:34 +02:00
|
|
|
|
|
2019-12-29 13:49:29 +01:00
|
|
|
|
const attrs = {};
|
2022-03-17 00:31:13 +01:00
|
|
|
|
const $span_stub = $("<span>");
|
2017-06-02 16:38:34 +02:00
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
|
$span_stub.attr = (name, val) => {
|
2019-12-29 13:49:29 +01:00
|
|
|
|
attrs[name] = val;
|
2022-01-25 11:36:19 +01:00
|
|
|
|
return $span_stub;
|
2017-06-02 16:38:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
|
$span_stub.append = (str) => {
|
|
|
|
|
$span_stub.html(str);
|
|
|
|
|
return $span_stub;
|
2017-06-02 16:38:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2022-09-29 19:17:17 +02:00
|
|
|
|
const $actual = timerender.render_date(message_time, today);
|
2022-01-25 11:36:19 +01:00
|
|
|
|
assert.equal($actual.html(), expected_html);
|
2023-01-08 18:08:49 +01:00
|
|
|
|
assert.equal(attrs["data-tippy-content"], "Friday, April 12, 2019");
|
2020-07-15 01:29:15 +02:00
|
|
|
|
assert.equal(attrs.class, "timerender0");
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("get_full_time", () => {
|
2022-02-09 14:56:52 +01:00
|
|
|
|
const timestamp = date_2017.getTime() / 1000;
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const expected = "2017-05-18T07:12:53Z"; // ISO 8601 date format
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const actual = timerender.get_full_time(timestamp);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("get_timestamp_for_flatpickr", () => {
|
2020-07-06 19:09:29 +02:00
|
|
|
|
const func = timerender.get_timestamp_for_flatpickr;
|
2020-07-07 05:25:09 +02:00
|
|
|
|
// Freeze time for testing.
|
2022-02-09 14:56:52 +01:00
|
|
|
|
MockDate.set(date_2017.getTime());
|
2020-07-07 05:25:09 +02:00
|
|
|
|
|
2023-04-11 02:32:07 +02:00
|
|
|
|
// Invalid timestamps should show current time on the hour.
|
|
|
|
|
const date_without_minutes = new Date();
|
|
|
|
|
date_without_minutes.setMinutes(0, 0);
|
|
|
|
|
assert.equal(func("random str").valueOf(), date_without_minutes.getTime());
|
2020-07-07 05:25:09 +02:00
|
|
|
|
|
2022-02-09 14:56:52 +01:00
|
|
|
|
// Valid ISO timestamps should return the timestamp.
|
|
|
|
|
assert.equal(func(date_2017.toISOString()).valueOf(), date_2017.getTime());
|
2020-07-07 05:25:09 +02:00
|
|
|
|
|
|
|
|
|
// Restore the Date object.
|
2021-02-05 22:46:37 +01:00
|
|
|
|
MockDate.reset();
|
2020-07-06 19:09:29 +02:00
|
|
|
|
});
|
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("absolute_time_12_hour", () => {
|
2021-07-28 16:00:58 +02:00
|
|
|
|
user_settings.twenty_four_hour_time = false;
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2017-07-26 07:20:31 +02:00
|
|
|
|
// timestamp with hour > 12, same year
|
2022-02-09 14:56:52 +01:00
|
|
|
|
let timestamp = date_2019.getTime();
|
|
|
|
|
|
|
|
|
|
let today = date_2019;
|
2023-03-16 19:40:55 +01:00
|
|
|
|
let expected = "Apr 12, 5:52 PM";
|
2019-11-02 00:06:25 +01:00
|
|
|
|
let actual = timerender.absolute_time(timestamp, today);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual, expected);
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2017-07-26 07:20:31 +02:00
|
|
|
|
// timestamp with hour > 12, different year
|
2022-02-09 14:56:52 +01:00
|
|
|
|
let next_year = add(today, {years: 1});
|
2023-03-16 19:40:55 +01:00
|
|
|
|
expected = "Apr 12, 2019, 5:52 PM";
|
2022-02-09 14:56:52 +01:00
|
|
|
|
actual = timerender.absolute_time(timestamp, next_year);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual, expected);
|
2017-07-26 07:20:31 +02:00
|
|
|
|
|
|
|
|
|
// timestamp with hour < 12, same year
|
2022-02-09 14:56:52 +01:00
|
|
|
|
timestamp = date_2017.getTime();
|
|
|
|
|
|
|
|
|
|
today = date_2017;
|
2023-03-16 19:40:55 +01:00
|
|
|
|
expected = "May 18, 7:12 AM";
|
2017-07-26 07:20:31 +02:00
|
|
|
|
actual = timerender.absolute_time(timestamp, today);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual, expected);
|
2017-07-26 07:20:31 +02:00
|
|
|
|
|
|
|
|
|
// timestamp with hour < 12, different year
|
2022-02-09 14:56:52 +01:00
|
|
|
|
next_year = add(today, {years: 1});
|
2023-03-16 19:40:55 +01:00
|
|
|
|
expected = "May 18, 2017, 7:12 AM";
|
2022-02-09 14:56:52 +01:00
|
|
|
|
actual = timerender.absolute_time(timestamp, next_year);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("absolute_time_24_hour", () => {
|
2021-07-28 16:00:58 +02:00
|
|
|
|
user_settings.twenty_four_hour_time = true;
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2022-02-09 14:56:52 +01:00
|
|
|
|
// date with hour > 12, same year
|
|
|
|
|
let today = date_2019;
|
2023-01-08 18:08:49 +01:00
|
|
|
|
let expected = "Apr 12, 17:52";
|
2022-02-09 14:56:52 +01:00
|
|
|
|
let actual = timerender.absolute_time(date_2019.getTime(), today);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual, expected);
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2022-02-09 14:56:52 +01:00
|
|
|
|
// date with hour > 12, different year
|
|
|
|
|
let next_year = add(today, {years: 1});
|
|
|
|
|
|
2023-01-08 18:08:49 +01:00
|
|
|
|
expected = "Apr 12, 2019, 17:52";
|
2022-02-09 14:56:52 +01:00
|
|
|
|
actual = timerender.absolute_time(date_2019.getTime(), next_year);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual, expected);
|
2017-07-26 07:20:31 +02:00
|
|
|
|
|
|
|
|
|
// timestamp with hour < 12, same year
|
2022-02-09 14:56:52 +01:00
|
|
|
|
today = date_2017;
|
2023-01-08 18:08:49 +01:00
|
|
|
|
expected = "May 18, 07:12";
|
2022-02-09 14:56:52 +01:00
|
|
|
|
actual = timerender.absolute_time(date_2017.getTime(), today);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual, expected);
|
2017-07-26 07:20:31 +02:00
|
|
|
|
|
|
|
|
|
// timestamp with hour < 12, different year
|
2022-02-09 14:56:52 +01:00
|
|
|
|
next_year = add(today, {years: 1});
|
2023-01-08 18:08:49 +01:00
|
|
|
|
expected = "May 18, 2017, 07:12";
|
2022-02-09 14:56:52 +01:00
|
|
|
|
actual = timerender.absolute_time(date_2017.getTime(), next_year);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2021-06-25 19:52:04 +02:00
|
|
|
|
run_test("get_full_datetime", () => {
|
2022-02-09 14:56:52 +01:00
|
|
|
|
const time = date_2017_PM;
|
|
|
|
|
|
2023-03-16 19:40:55 +01:00
|
|
|
|
let expected = "translated: 5/18/2017 at 9:12:53 PM UTC";
|
2023-05-01 07:02:10 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime_clarification(time), expected);
|
|
|
|
|
expected = "translated: May 18, 2017 at 9:12:53 PM";
|
2021-06-27 19:16:36 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime(time), expected);
|
2017-06-02 16:38:34 +02:00
|
|
|
|
|
2023-04-29 01:29:13 +02:00
|
|
|
|
expected = "translated: 5/18/2017 at 9:12 PM UTC";
|
2023-05-01 07:02:10 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime_clarification(time, "time"), expected);
|
|
|
|
|
expected = "translated: May 18, 2017 at 9:12 PM";
|
2023-04-29 01:29:13 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime(time, "time"), expected);
|
|
|
|
|
|
2021-06-25 19:52:04 +02:00
|
|
|
|
// test 24 hour time setting.
|
2021-07-28 16:00:58 +02:00
|
|
|
|
user_settings.twenty_four_hour_time = true;
|
2021-06-27 19:16:36 +02:00
|
|
|
|
expected = "translated: 5/18/2017 at 21:12:53 UTC";
|
2023-05-01 07:02:10 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime_clarification(time), expected);
|
|
|
|
|
expected = "translated: May 18, 2017 at 21:12:53";
|
2021-06-27 19:16:36 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime(time), expected);
|
|
|
|
|
|
2021-07-28 16:00:58 +02:00
|
|
|
|
user_settings.twenty_four_hour_time = false;
|
2021-06-27 19:16:36 +02:00
|
|
|
|
|
|
|
|
|
// Test the GMT[+-]x:y logic.
|
2021-07-02 19:19:39 +02:00
|
|
|
|
const previous_env_tz = process.env.TZ;
|
2021-06-27 19:16:36 +02:00
|
|
|
|
process.env.TZ = "Asia/Kolkata";
|
2023-03-16 19:40:55 +01:00
|
|
|
|
expected = "translated: 5/19/2017 at 2:42:53 AM (UTC+05:30)";
|
2023-05-01 07:02:10 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime_clarification(time), expected);
|
|
|
|
|
expected = "translated: May 19, 2017 at 2:42:53 AM";
|
2021-06-27 19:16:36 +02:00
|
|
|
|
assert.equal(timerender.get_full_datetime(time), expected);
|
2021-07-02 19:19:39 +02:00
|
|
|
|
process.env.TZ = previous_env_tz;
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("last_seen_status_from_date", () => {
|
2020-10-02 11:46:25 +02:00
|
|
|
|
// Set base_date to March 1 2016 12.30 AM (months are zero based)
|
2021-02-05 21:20:14 +01:00
|
|
|
|
let base_date = new Date(2016, 2, 1, 0, 30);
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
function assert_same(duration, expected_status) {
|
|
|
|
|
const past_date = add(base_date, duration);
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const actual_status = timerender.last_seen_status_from_date(past_date, base_date);
|
2017-05-12 20:16:39 +02:00
|
|
|
|
assert.equal(actual_status, expected_status);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({minutes: -30}, $t({defaultMessage: "Active 30 minutes ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({hours: -1}, $t({defaultMessage: "Active an hour ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({hours: -2}, $t({defaultMessage: "Active 2 hours ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({hours: -20}, $t({defaultMessage: "Active 20 hours ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({hours: -24}, $t({defaultMessage: "Active yesterday"}));
|
2021-06-17 23:07:35 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({hours: -48}, $t({defaultMessage: "Active 2 days ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({days: -2}, $t({defaultMessage: "Active 2 days ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({days: -61}, $t({defaultMessage: "Active 61 days ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({days: -300}, $t({defaultMessage: "Active May 6, 2015"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({days: -366}, $t({defaultMessage: "Active Mar 1, 2015"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({years: -3}, $t({defaultMessage: "Active Mar 1, 2013"}));
|
2019-03-13 19:23:57 +01:00
|
|
|
|
|
2020-10-02 11:46:25 +02:00
|
|
|
|
// Set base_date to May 1 2016 12.30 AM (months are zero based)
|
2021-02-05 21:20:14 +01:00
|
|
|
|
base_date = new Date(2016, 4, 1, 0, 30);
|
2019-03-13 19:23:57 +01:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({days: -91}, $t({defaultMessage: "Active Jan 31"}));
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
|
|
|
|
// Set base_date to May 1 2016 10.30 PM (months are zero based)
|
2021-02-05 21:20:14 +01:00
|
|
|
|
base_date = new Date(2016, 4, 2, 23, 30);
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({hours: -1}, $t({defaultMessage: "Active an hour ago"}));
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({hours: -2}, $t({defaultMessage: "Active 2 hours ago"}));
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({hours: -12}, $t({defaultMessage: "Active 12 hours ago"}));
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
2023-04-07 18:24:15 +02:00
|
|
|
|
assert_same({hours: -24}, $t({defaultMessage: "Active yesterday"}));
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-12-25 21:43:06 +01:00
|
|
|
|
|
2023-04-08 02:13:36 +02:00
|
|
|
|
run_test("relative_time_string_from_date", () => {
|
|
|
|
|
// Set base_date to March 1 2016 12.30 AM (months are zero based)
|
|
|
|
|
let base_date = new Date(2016, 2, 1, 0, 30);
|
|
|
|
|
|
|
|
|
|
function assert_same(duration, expected_status) {
|
|
|
|
|
const past_date = add(base_date, duration);
|
2023-04-14 14:49:35 +02:00
|
|
|
|
const actual_status = timerender.relative_time_string_from_date({
|
|
|
|
|
date: past_date,
|
|
|
|
|
current_date: base_date,
|
|
|
|
|
});
|
2023-04-08 02:13:36 +02:00
|
|
|
|
assert.equal(actual_status, expected_status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert_same({seconds: -20}, $t({defaultMessage: "Just now"}));
|
|
|
|
|
|
|
|
|
|
assert_same({minutes: -1}, $t({defaultMessage: "Just now"}));
|
|
|
|
|
|
|
|
|
|
assert_same({minutes: -2}, $t({defaultMessage: "Just now"}));
|
|
|
|
|
|
|
|
|
|
assert_same({minutes: -30}, $t({defaultMessage: "30 minutes ago"}));
|
|
|
|
|
|
|
|
|
|
assert_same({hours: -1}, $t({defaultMessage: "An hour ago"}));
|
|
|
|
|
|
|
|
|
|
assert_same({hours: -2}, $t({defaultMessage: "2 hours ago"}));
|
|
|
|
|
|
|
|
|
|
assert_same({hours: -20}, $t({defaultMessage: "20 hours ago"}));
|
|
|
|
|
|
|
|
|
|
assert_same({hours: -24}, $t({defaultMessage: "Yesterday"}));
|
|
|
|
|
|
|
|
|
|
assert_same({hours: -48}, $t({defaultMessage: "2 days ago"}));
|
|
|
|
|
|
|
|
|
|
assert_same({days: -2}, $t({defaultMessage: "2 days ago"}));
|
|
|
|
|
|
|
|
|
|
assert_same({days: -61}, $t({defaultMessage: "61 days ago"}));
|
|
|
|
|
|
|
|
|
|
assert_same({days: -300}, "May 6, 2015");
|
|
|
|
|
|
|
|
|
|
assert_same({days: -366}, "Mar 1, 2015");
|
|
|
|
|
|
|
|
|
|
assert_same({years: -3}, "Mar 1, 2013");
|
|
|
|
|
|
|
|
|
|
// Set base_date to May 1 2016 12.30 AM (months are zero based)
|
|
|
|
|
base_date = new Date(2016, 4, 1, 0, 30);
|
|
|
|
|
|
|
|
|
|
assert_same({days: -91}, "Jan 31");
|
|
|
|
|
|
|
|
|
|
// Set base_date to May 1 2016 10.30 PM (months are zero based)
|
|
|
|
|
base_date = new Date(2016, 4, 2, 23, 30);
|
|
|
|
|
|
|
|
|
|
assert_same({hours: -1}, $t({defaultMessage: "An hour ago"}));
|
|
|
|
|
|
|
|
|
|
assert_same({hours: -2}, $t({defaultMessage: "2 hours ago"}));
|
|
|
|
|
|
|
|
|
|
assert_same({hours: -12}, $t({defaultMessage: "12 hours ago"}));
|
|
|
|
|
|
|
|
|
|
assert_same({hours: -24}, $t({defaultMessage: "Yesterday"}));
|
|
|
|
|
});
|
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("set_full_datetime", () => {
|
2022-02-09 14:56:52 +01:00
|
|
|
|
let time = date_2019;
|
2021-03-14 15:57:08 +01:00
|
|
|
|
|
2021-07-28 16:00:58 +02:00
|
|
|
|
user_settings.twenty_four_hour_time = true;
|
2019-11-02 00:06:25 +01:00
|
|
|
|
let time_str = timerender.stringify_time(time);
|
2022-02-09 14:56:52 +01:00
|
|
|
|
let expected = "17:52";
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(time_str, expected);
|
2017-12-25 21:43:06 +01:00
|
|
|
|
|
2021-07-28 16:00:58 +02:00
|
|
|
|
user_settings.twenty_four_hour_time = false;
|
2017-12-25 21:43:06 +01:00
|
|
|
|
time_str = timerender.stringify_time(time);
|
2023-03-16 19:40:55 +01:00
|
|
|
|
expected = "5:52 PM";
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(time_str, expected);
|
2017-12-25 21:43:06 +01:00
|
|
|
|
|
2022-02-09 14:56:52 +01:00
|
|
|
|
time = add(time, {hours: -7}); // time between 1 to 12 o'clock time.
|
2021-07-28 16:00:58 +02:00
|
|
|
|
user_settings.twenty_four_hour_time = false;
|
2017-12-25 21:43:06 +01:00
|
|
|
|
time_str = timerender.stringify_time(time);
|
2023-03-16 19:40:55 +01:00
|
|
|
|
expected = "10:52 AM";
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(time_str, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2023-08-11 19:46:58 +02:00
|
|
|
|
|
|
|
|
|
run_test("should_display_profile_incomplete_alert", () => {
|
|
|
|
|
// Organization created < 15 days ago
|
|
|
|
|
let realm_date_created = new Date();
|
|
|
|
|
realm_date_created.setDate(realm_date_created.getDate() - 5);
|
|
|
|
|
|
|
|
|
|
assert.equal(timerender.should_display_profile_incomplete_alert(realm_date_created), false);
|
|
|
|
|
|
|
|
|
|
// Organization created > 15 days ago
|
|
|
|
|
realm_date_created = new Date();
|
|
|
|
|
realm_date_created.setDate(realm_date_created.getDate() - 15);
|
|
|
|
|
|
|
|
|
|
assert.equal(timerender.should_display_profile_incomplete_alert(realm_date_created), true);
|
|
|
|
|
});
|