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
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
const {$t} = require("../zjsunit/i18n");
|
2021-06-16 15:58:34 +02:00
|
|
|
|
const {zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-02-21 15:38:51 +01:00
|
|
|
|
const $ = require("../zjsunit/zjquery");
|
2021-03-25 22:35:45 +01:00
|
|
|
|
const {page_params} = require("../zjsunit/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
|
2021-03-25 22:35:45 +01:00
|
|
|
|
page_params.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
|
|
|
|
|
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 = {
|
2021-04-13 06:51:54 +02:00
|
|
|
|
time_str: $t({defaultMessage: "Today"}),
|
2020-07-15 01:29:15 +02: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", () => {
|
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 = {
|
2021-04-13 06:51:54 +02:00
|
|
|
|
time_str: $t({defaultMessage: "Yesterday"}),
|
2020-07-15 01:29:15 +02: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", () => {
|
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-03-14 15:57:08 +01:00
|
|
|
|
timerender.clear_for_testing();
|
|
|
|
|
|
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;
|
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 = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const span_stub = $("<span />");
|
2017-06-02 16:38:34 +02:00
|
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
|
span_stub.attr = (name, val) => {
|
2019-12-29 13:49:29 +01:00
|
|
|
|
attrs[name] = val;
|
2017-06-02 16:38:34 +02:00
|
|
|
|
return span_stub;
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
|
span_stub.append = (str) => {
|
2017-06-02 16:38:34 +02:00
|
|
|
|
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);
|
2021-06-23 22:16:15 +02: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("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;
|
2021-02-23 14:37:26 +01:00
|
|
|
|
span_stub.append = (val) => {
|
2017-06-02 16:38:34 +02:00
|
|
|
|
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>',
|
2021-04-13 06:51:54 +02:00
|
|
|
|
$t({defaultMessage: "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>',
|
2021-04-13 06:51:54 +02:00
|
|
|
|
$t({defaultMessage: "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", () => {
|
2021-03-25 22:35:45 +01:00
|
|
|
|
page_params.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
|
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", () => {
|
2021-03-25 22:35:45 +01:00
|
|
|
|
page_params.twenty_four_hour_time = true;
|
2017-05-18 21:18:11 +02:00
|
|
|
|
|
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
|
|
|
|
|
2021-06-25 19:52:04 +02:00
|
|
|
|
run_test("get_full_datetime", () => {
|
|
|
|
|
const time = new Date(1495141973000); // 2017/5/18 9:12:53 PM (UTC+0)
|
2021-06-27 19:16:36 +02:00
|
|
|
|
let expected = "translated: 5/18/2017 at 9:12:53 PM UTC";
|
|
|
|
|
assert.equal(timerender.get_full_datetime(time), expected);
|
2017-06-02 16:38:34 +02:00
|
|
|
|
|
2021-06-25 19:52:04 +02:00
|
|
|
|
// test 24 hour time setting.
|
2021-06-12 22:10:34 +02:00
|
|
|
|
page_params.twenty_four_hour_time = true;
|
2021-06-27 19:16:36 +02:00
|
|
|
|
expected = "translated: 5/18/2017 at 21:12:53 UTC";
|
|
|
|
|
assert.equal(timerender.get_full_datetime(time), expected);
|
|
|
|
|
|
|
|
|
|
page_params.twenty_four_hour_time = false;
|
|
|
|
|
|
|
|
|
|
// 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";
|
|
|
|
|
expected = "translated: 5/19/2017 at 2:42:53 AM (UTC+5.5)";
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({seconds: -20}, $t({defaultMessage: "Just now"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({minutes: -1}, $t({defaultMessage: "Just now"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({minutes: -2}, $t({defaultMessage: "Just now"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({minutes: -30}, $t({defaultMessage: "30 minutes ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-06-17 23:07:35 +02:00
|
|
|
|
assert_same({hours: -1}, $t({defaultMessage: "An hour ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-06-17 23:07:35 +02:00
|
|
|
|
assert_same({hours: -2}, $t({defaultMessage: "2 hours ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-06-17 23:07:35 +02:00
|
|
|
|
assert_same({hours: -20}, $t({defaultMessage: "20 hours ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-06-17 23:07:35 +02:00
|
|
|
|
assert_same({hours: -24}, $t({defaultMessage: "Yesterday"}));
|
|
|
|
|
|
|
|
|
|
assert_same({hours: -48}, $t({defaultMessage: "2 days ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({days: -2}, $t({defaultMessage: "2 days ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({days: -61}, $t({defaultMessage: "61 days ago"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({days: -300}, $t({defaultMessage: "May 06,\u00A02015"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({days: -366}, $t({defaultMessage: "Mar 01,\u00A02015"}));
|
2017-05-12 20:16:39 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({years: -3}, $t({defaultMessage: "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-04-13 06:51:54 +02:00
|
|
|
|
assert_same({days: -91}, $t({defaultMessage: "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-04-13 06:51:54 +02:00
|
|
|
|
assert_same({hours: -1}, $t({defaultMessage: "An hour ago"}));
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({hours: -2}, $t({defaultMessage: "2 hours ago"}));
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({hours: -12}, $t({defaultMessage: "12 hours ago"}));
|
2020-10-02 11:46:25 +02:00
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
|
assert_same({hours: -24}, $t({defaultMessage: "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)
|
2021-03-14 15:57:08 +01:00
|
|
|
|
|
|
|
|
|
page_params.twenty_four_hour_time = true;
|
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
|
|
|
|
});
|