eslint: Fix unicorn/prefer-date-now.

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v24.0.0/docs/rules/prefer-date-now.md

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-12-22 02:54:49 -08:00
committed by Tim Abbott
parent 2f80415756
commit dd8e14d3e6
10 changed files with 13 additions and 13 deletions

View File

@@ -54,7 +54,7 @@ function stub_timestamp(timestamp, func) {
function fake_time() { function fake_time() {
return timestamp; return timestamp;
} }
with_field(Date.prototype, "getTime", fake_time, func); with_field(Date, "now", fake_time, func);
} }
const legacy_draft = { const legacy_draft = {

View File

@@ -11,9 +11,9 @@
to the console along with the name "foo". */ to the console along with the name "foo". */
export function print_elapsed_time(name, fun) { export function print_elapsed_time(name, fun) {
const t0 = new Date().getTime(); const t0 = Date.now();
const out = fun(); const out = fun();
const t1 = new Date().getTime(); const t1 = Date.now();
console.log(name + ": " + (t1 - t0) + " ms"); console.log(name + ": " + (t1 - t0) + " ms");
return out; return out;
} }

View File

@@ -23,7 +23,7 @@ const draft_model = (function () {
ls.version = 1; ls.version = 1;
function getTimestamp() { function getTimestamp() {
return new Date().getTime(); return Date.now();
} }
function get() { function get() {

View File

@@ -33,7 +33,7 @@ const animate = {
return; return;
} }
if (meta.hide_me_time < new Date().getTime() && !meta.alert_hover_state) { if (meta.hide_me_time < Date.now() && !meta.alert_hover_state) {
animate.fadeOut(); animate.fadeOut();
return; return;
} }
@@ -89,7 +89,7 @@ function set_up_handlers() {
meta.alert_hover_state = false; meta.alert_hover_state = false;
// add at least 2000ms but if more than that exists just keep the // add at least 2000ms but if more than that exists just keep the
// current amount. // current amount.
meta.hide_me_time = Math.max(meta.hide_me_time, new Date().getTime() + 2000); meta.hide_me_time = Math.max(meta.hide_me_time, Date.now() + 2000);
}); });
meta.$container.on("click", ".exit-me", () => { meta.$container.on("click", ".exit-me", () => {
@@ -128,7 +128,7 @@ exports.show = function (opts) {
meta.undo = opts.on_undo; meta.undo = opts.on_undo;
// add a four second delay before closing up. // add a four second delay before closing up.
meta.hide_me_time = new Date().getTime() + 4000; meta.hide_me_time = Date.now() + 4000;
meta.$container.find(".feedback_title").text(opts.title_text); meta.$container.find(".feedback_title").text(opts.title_text);
meta.$container.find(".feedback_undo").text(opts.undo_button_text); meta.$container.find(".feedback_undo").text(opts.undo_button_text);

View File

@@ -26,7 +26,7 @@ const ls = {
return { return {
data, data,
__valid: true, __valid: true,
expires: new Date().getTime() + expires, expires: Date.now() + expires,
}; };
}, },

View File

@@ -758,7 +758,7 @@ exports.save_message_row_edit = function (row) {
// Settings these attributes causes a "SAVING" notice to // Settings these attributes causes a "SAVING" notice to
// briefly appear where "EDITED" would normally appear until // briefly appear where "EDITED" would normally appear until
// the message is acknowledged by the server. // the message is acknowledged by the server.
message.local_edit_timestamp = Math.round(new Date().getTime() / 1000); message.local_edit_timestamp = Math.round(Date.now() / 1000);
echo.edit_locally(message, currently_echoing_messages.get(message_id)); echo.edit_locally(message, currently_echoing_messages.get(message_id));

View File

@@ -4,7 +4,7 @@ const render_muted_topic_ui_row = require("../templates/muted_topic_ui_row.hbs")
const render_topic_muted = require("../templates/topic_muted.hbs"); const render_topic_muted = require("../templates/topic_muted.hbs");
function timestamp_ms() { function timestamp_ms() {
return new Date().getTime(); return Date.now();
} }
let last_topic_update = 0; let last_topic_update = 0;

View File

@@ -1260,7 +1260,7 @@ exports.register_click_handlers = function () {
return; return;
} }
const date = new Date().getTime(); const date = Date.now();
// only run `popovers.hide_all()` if the last scroll was more // only run `popovers.hide_all()` if the last scroll was more
// than 250ms ago. // than 250ms ago.

View File

@@ -15,7 +15,7 @@ $(() => {
page_params.needs_tutorial = false; page_params.needs_tutorial = false;
} }
page_params.page_load_time = new Date().getTime(); page_params.page_load_time = Date.now();
// Display loading indicator. This disappears after the first // Display loading indicator. This disappears after the first
// get_events completes. // get_events completes.

View File

@@ -43,7 +43,7 @@ function is_valid_conversation() {
} }
function get_current_time() { function get_current_time() {
return new Date().getTime(); return Date.now();
} }
function notify_server_start(user_ids_array) { function notify_server_start(user_ids_array) {