mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 21:33:38 +08:00
DEV: prefer Date.now() over new Date().getTime()
`New Date().getTime()` is both uglier and slower than `Date.now()` `Date.now()` is available on all the browsers we support.
This commit is contained in:
parent
25f1f23288
commit
e62071830d
|
@ -112,7 +112,7 @@ export default Component.extend({
|
|||
return;
|
||||
}
|
||||
|
||||
const t0 = new Date().getTime();
|
||||
const t0 = Date.now();
|
||||
const args = this.args || this.buildArgs();
|
||||
const opts = {
|
||||
model: this.model,
|
||||
|
@ -139,7 +139,7 @@ export default Component.extend({
|
|||
|
||||
if (this.profileWidget) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(new Date().getTime() - t0);
|
||||
console.log(Date.now() - t0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ export default Component.extend({
|
|||
},
|
||||
hideForSession() {
|
||||
this.session.set("hideSignupCta", true);
|
||||
this.keyValueStore.setItem("anon-cta-hidden", new Date().getTime());
|
||||
this.keyValueStore.setItem("anon-cta-hidden", Date.now());
|
||||
later(() => this.session.set("showSignupCta", false), 20 * 1000);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -38,7 +38,7 @@ export default {
|
|||
return; // hidden forever
|
||||
}
|
||||
|
||||
const now = new Date().getTime();
|
||||
const now = Date.now();
|
||||
const hiddenAt = keyValueStore.getInt("anon-cta-hidden", 0);
|
||||
if (hiddenAt > now - PROMPT_HIDE_DURATION) {
|
||||
return; // hidden in last 24 hours
|
||||
|
|
|
@ -49,7 +49,7 @@ export default class LockOn {
|
|||
}
|
||||
|
||||
lock() {
|
||||
const startedAt = new Date().getTime();
|
||||
const startedAt = Date.now();
|
||||
let previousTop = this.elementTop();
|
||||
previousTop && $(window).scrollTop(previousTop);
|
||||
|
||||
|
@ -73,7 +73,7 @@ export default class LockOn {
|
|||
}
|
||||
|
||||
// Stop after a little while
|
||||
if (new Date().getTime() - startedAt > LOCK_DURATION_MS) {
|
||||
if (Date.now() - startedAt > LOCK_DURATION_MS) {
|
||||
return this.clearLock(interval);
|
||||
}
|
||||
}, 50);
|
||||
|
|
|
@ -65,7 +65,7 @@ export default class {
|
|||
|
||||
// Reset our timers
|
||||
reset() {
|
||||
const now = new Date().getTime();
|
||||
const now = Date.now();
|
||||
this._lastTick = now;
|
||||
this._lastScrolled = now;
|
||||
this._lastFlush = 0;
|
||||
|
@ -79,7 +79,7 @@ export default class {
|
|||
}
|
||||
|
||||
scrolled() {
|
||||
this._lastScrolled = new Date().getTime();
|
||||
this._lastScrolled = Date.now();
|
||||
}
|
||||
|
||||
registerAnonCallback(cb) {
|
||||
|
@ -212,7 +212,7 @@ export default class {
|
|||
}
|
||||
|
||||
tick() {
|
||||
const now = new Date().getTime();
|
||||
const now = Date.now();
|
||||
|
||||
// If the user hasn't scrolled the browser in a long time, stop tracking time read
|
||||
const sinceScrolled = now - this._lastScrolled;
|
||||
|
|
|
@ -368,7 +368,7 @@ const DiscourseURL = EmberObject.extend({
|
|||
const closest = postStream.closestPostNumberFor(opts.nearPost || 1);
|
||||
topicController.setProperties({
|
||||
"model.currentPost": closest,
|
||||
enteredAt: new Date().getTime().toString()
|
||||
enteredAt: Date.now().toString()
|
||||
});
|
||||
|
||||
this.appEvents.trigger("post:highlight", closest);
|
||||
|
|
|
@ -61,7 +61,7 @@ export default Mixin.create({
|
|||
if (e.type === "pointerup" || e.type === "pointercancel") {
|
||||
return oldState;
|
||||
}
|
||||
const newTimestamp = new Date().getTime();
|
||||
const newTimestamp = Date.now();
|
||||
const timeDiffSeconds = newTimestamp - oldState.timestamp;
|
||||
if (timeDiffSeconds === 0) {
|
||||
return oldState;
|
||||
|
@ -109,7 +109,7 @@ export default Mixin.create({
|
|||
deltaY: 0,
|
||||
distance: 0,
|
||||
start: true,
|
||||
timestamp: new Date().getTime(),
|
||||
timestamp: Date.now(),
|
||||
direction: null
|
||||
};
|
||||
this.set("_panState", newState);
|
||||
|
|
|
@ -53,7 +53,7 @@ export default DiscourseRoute.extend({
|
|||
topicController.setProperties({
|
||||
"model.currentPost": closest,
|
||||
enteredIndex: topic.postStream.progressIndexOfPost(closestPost),
|
||||
enteredAt: new Date().getTime().toString()
|
||||
enteredAt: Date.now().toString()
|
||||
});
|
||||
|
||||
this.appEvents.trigger("page:topic-loaded", topic);
|
||||
|
|
|
@ -13,7 +13,7 @@ export function historyHeat(siteSettings, updatedAt) {
|
|||
}
|
||||
|
||||
// Show heat on age
|
||||
const rightNow = new Date().getTime();
|
||||
const rightNow = Date.now();
|
||||
const updatedAtTime = updatedAt.getTime();
|
||||
|
||||
if (updatedAtTime > rightNow - mult(siteSettings.history_hours_low)) {
|
||||
|
|
|
@ -730,7 +730,7 @@ export default createWidget("post", {
|
|||
const lastWarnedLikes = kvs.get("lastWarnedLikes");
|
||||
|
||||
// only warn once per day
|
||||
const yesterday = new Date().getTime() - 1000 * 60 * 60 * 24;
|
||||
const yesterday = Date.now() - 1000 * 60 * 60 * 24;
|
||||
if (lastWarnedLikes && parseInt(lastWarnedLikes, 10) > yesterday) {
|
||||
return;
|
||||
}
|
||||
|
@ -739,7 +739,7 @@ export default createWidget("post", {
|
|||
const threshold = Math.ceil(max * 0.1);
|
||||
if (remaining === threshold) {
|
||||
bootbox.alert(I18n.t("post.few_likes_left"));
|
||||
kvs.set({ key: "lastWarnedLikes", value: new Date().getTime() });
|
||||
kvs.set({ key: "lastWarnedLikes", value: Date.now() });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user