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
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
|
const {run_test} = require("../zjsunit/test");
|
2020-12-01 00:12:33 +01:00
|
|
|
|
const {make_zjquery} = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
|
2020-12-01 00:12:33 +01:00
|
|
|
|
set_global("$", make_zjquery());
|
2020-07-15 01:29:15 +02:00
|
|
|
|
set_global("page_params", {
|
2017-12-25 21:43:06 +01:00
|
|
|
|
twenty_four_hour_time: true,
|
|
|
|
|
});
|
2020-07-24 06:02:07 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
zrequire("timerender");
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("render_now_returns_today", () => {
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const today = new Date(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = {
|
2020-07-15 01:29:15 +02:00
|
|
|
|
time_str: i18n.t("Today"),
|
|
|
|
|
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", () => {
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const today = new Date(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
|
|
|
|
|
const yesterday = add(today, {days: -1});
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = {
|
2020-07-15 01:29:15 +02:00
|
|
|
|
time_str: i18n.t("Yesterday"),
|
|
|
|
|
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", () => {
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const today = new Date(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
|
|
|
|
|
const year_ago = add(today, {years: -1});
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = {
|
2020-07-15 01:29:15 +02: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", () => {
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const today = new Date(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
|
|
|
|
|
const three_months_ago = add(today, {months: -3});
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = {
|
2020-07-15 01:29:15 +02: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
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("render_now_returns_year_with_year_boundary", () => {
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const today = new Date(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
|
|
|
|
|
const six_months_ago = add(today, {months: -6});
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = {
|
2020-07-15 01:29:15 +02: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-02-05 21:20:14 +01:00
|
|
|
|
const today = new Date(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
|
|
|
|
|
const message_time = today;
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const expected_html = i18n.t("Today");
|
2017-06-02 16:38:34 +02:00
|
|
|
|
|
2019-12-29 13:49:29 +01:00
|
|
|
|
const attrs = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const span_stub = $("<span />");
|
2017-06-02 16:38:34 +02:00
|
|
|
|
|
|
|
|
|
span_stub.attr = function (name, val) {
|
2019-12-29 13:49:29 +01:00
|
|
|
|
attrs[name] = val;
|
2017-06-02 16:38:34 +02:00
|
|
|
|
return span_stub;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
span_stub.append = function (str) {
|
|
|
|
|
span_stub.html(str);
|
|
|
|
|
return span_stub;
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const actual = timerender.render_date(message_time, undefined, today);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(actual.html(), expected_html);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
assert.equal(attrs.title, "Friday, April 12, 2019");
|
|
|
|
|
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("render_date_renders_time_above_html", () => {
|
2021-02-05 21:20:14 +01:00
|
|
|
|
const today = new Date(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
|
|
|
|
|
const message_time = today;
|
|
|
|
|
const message_time_above = add(today, {days: -1});
|
2017-06-02 16:38:34 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const span_stub = $("<span />");
|
2017-06-02 16:38:34 +02:00
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
|
let appended_val;
|
2017-06-02 16:38:34 +02:00
|
|
|
|
span_stub.append = function (val) {
|
|
|
|
|
appended_val = val;
|
|
|
|
|
return span_stub;
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const expected = [
|
2018-10-15 15:52:54 +02:00
|
|
|
|
'<i class="date-direction fa fa-caret-up"></i>',
|
2020-07-15 01:29:15 +02:00
|
|
|
|
i18n.t("Yesterday"),
|
2017-06-02 16:38:34 +02:00
|
|
|
|
'<hr class="date-line">',
|
2018-10-15 15:52:54 +02:00
|
|
|
|
'<i class="date-direction fa fa-caret-down"></i>',
|
2020-07-15 01:29:15 +02:00
|
|
|
|
i18n.t("Today"),
|
2017-06-02 16:38:34 +02:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
timerender.render_date(message_time, message_time_above, today);
|
|
|
|
|
assert.deepEqual(appended_val, 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_full_time", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const timestamp = 1495091573; // 5/18/2017 7:12:53 AM (UTC+0)
|
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 unix_timestamp = 1495091573000; // 5/18/2017 7:12:53 AM (UTC+0)
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const iso_timestamp = "2017-05-18T07:12:53Z"; // ISO 8601 date format
|
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.
|
2021-02-05 22:46:37 +01:00
|
|
|
|
MockDate.set(new Date("2020-07-07T10:00:00Z").getTime());
|
2020-07-07 05:25:09 +02:00
|
|
|
|
|
2020-07-06 19:09:29 +02:00
|
|
|
|
// Invalid timestamps should show current time.
|
2021-02-05 22:46:37 +01:00
|
|
|
|
assert.equal(func("random str").valueOf(), Date.now());
|
2020-07-07 05:25:09 +02:00
|
|
|
|
|
2020-07-06 19:09:29 +02:00
|
|
|
|
// Valid ISO timestamps should return Date objects.
|
2021-02-05 22:46:37 +01:00
|
|
|
|
assert.equal(func(iso_timestamp).valueOf(), new Date(unix_timestamp).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", () => {
|
|
|
|
|
set_global("page_params", {
|
2017-05-18 21:18:11 +02:00
|
|
|
|
twenty_four_hour_time: false,
|
|
|
|
|
});
|
|
|
|
|
|
2017-07-26 07:20:31 +02:00
|
|
|
|
// timestamp with hour > 12, same year
|
2019-11-02 00:06:25 +01:00
|
|
|
|
let timestamp = 1555091573000; // 4/12/2019 5:52:53 PM (UTC+0)
|
|
|
|
|
let today = new Date(timestamp);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
let expected = "Apr 12 05: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
|
|
|
|
|
today.setFullYear(today.getFullYear() + 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
expected = "Apr 12, 2019 05:52 PM";
|
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, same year
|
2017-05-18 21:18:11 +02:00
|
|
|
|
timestamp = 1495091573000; // 5/18/2017 7:12:53 AM (UTC+0)
|
2017-07-26 07:20:31 +02:00
|
|
|
|
today = new Date(timestamp);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
expected = "May 18 07: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
|
|
|
|
|
today.setFullYear(today.getFullYear() + 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
expected = "May 18, 2017 07: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);
|
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", () => {
|
|
|
|
|
set_global("page_params", {
|
2017-05-18 21:18:11 +02:00
|
|
|
|
twenty_four_hour_time: true,
|
|
|
|
|
});
|
|
|
|
|
|
2017-07-26 07:20:31 +02:00
|
|
|
|
// timestamp with hour > 12, same year
|
2019-11-02 00:06:25 +01:00
|
|
|
|
let timestamp = 1555091573000; // 4/12/2019 5:52:53 PM (UTC+0)
|
|
|
|
|
let today = new Date(timestamp);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
let expected = "Apr 12 17:52";
|
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
|
|
|
|
|
today.setFullYear(today.getFullYear() + 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
expected = "Apr 12, 2019 17:52";
|
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, same year
|
2017-05-18 21:18:11 +02:00
|
|
|
|
timestamp = 1495091573000; // 5/18/2017 7:12:53 AM (UTC+0)
|
2017-07-26 07:20:31 +02:00
|
|
|
|
today = new Date(timestamp);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
expected = "May 18 07:12";
|
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
|
|
|
|
|
today.setFullYear(today.getFullYear() + 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
expected = "May 18, 2017 07:12";
|
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);
|
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("set_full_datetime", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const message = {
|
2019-06-04 04:28:47 +02:00
|
|
|
|
timestamp: 1495091573, // 2017/5/18 7:12:53 AM (UTC+0)
|
2017-05-18 21:18:11 +02:00
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const time_element = $("<span/>");
|
2019-12-29 13:49:29 +01:00
|
|
|
|
const attrs = {};
|
2017-06-02 16:38:34 +02:00
|
|
|
|
|
|
|
|
|
time_element.attr = function (name, val) {
|
2019-12-29 13:49:29 +01:00
|
|
|
|
attrs[name] = val;
|
2017-06-02 16:38:34 +02:00
|
|
|
|
return time_element;
|
|
|
|
|
};
|
|
|
|
|
|
2019-06-04 04:28:47 +02:00
|
|
|
|
// The formatting of the string time.toLocale(Date|Time)String() on Node
|
|
|
|
|
// might differ from the browser.
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const time = new Date(message.timestamp * 1000);
|
|
|
|
|
const expected = `${time.toLocaleDateString()} 7:12:53 AM (UTC+0)`;
|
2017-05-18 21:18:11 +02:00
|
|
|
|
timerender.set_full_datetime(message, time_element);
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(attrs.title, expected);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({seconds: -20}, i18n.t("Just now"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({minutes: -1}, i18n.t("Just now"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({minutes: -2}, i18n.t("Just now"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({minutes: -30}, i18n.t("30 minutes ago"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({hours: -1}, i18n.t("Yesterday"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({hours: -2}, i18n.t("Yesterday"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({hours: -20}, i18n.t("Yesterday"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({days: -1}, i18n.t("Yesterday"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({days: -2}, i18n.t("2 days ago"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({days: -61}, i18n.t("61 days ago"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({days: -300}, i18n.t("May 06,\u00A02015"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({days: -366}, i18n.t("Mar 01,\u00A02015"));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({years: -3}, i18n.t("Mar 01,\u00A02013"));
|
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
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({days: -91}, i18n.t("Jan\u00A031"));
|
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
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({hours: -1}, i18n.t("An hour ago"));
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({hours: -2}, i18n.t("2 hours ago"));
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({hours: -12}, i18n.t("12 hours ago"));
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
assert_same({hours: -24}, i18n.t("Yesterday"));
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2017-12-25 21:43:06 +01:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("set_full_datetime", () => {
|
2021-02-05 21:20:14 +01:00
|
|
|
|
let time = new Date(1549958107000); // Tuesday 2/12/2019 07:55:07 AM (UTC+0)
|
2019-11-02 00:06:25 +01:00
|
|
|
|
let time_str = timerender.stringify_time(time);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
let expected = "07:55";
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(time_str, expected);
|
2017-12-25 21:43:06 +01:00
|
|
|
|
|
|
|
|
|
page_params.twenty_four_hour_time = false;
|
|
|
|
|
time_str = timerender.stringify_time(time);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
expected = "7:55 AM";
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(time_str, expected);
|
2017-12-25 21:43:06 +01:00
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
|
time = new Date(1549979707000); // Tuesday 2/12/2019 13:55:07 PM (UTC+0)
|
2017-12-25 21:43:06 +01:00
|
|
|
|
page_params.twenty_four_hour_time = false;
|
|
|
|
|
time_str = timerender.stringify_time(time);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
expected = "1:55 PM";
|
2020-07-28 17:00:59 +02:00
|
|
|
|
assert.equal(time_str, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|