mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-09-13 18:16:48 +08:00
Using date-fns instead of moment (#2707)
* installed date fns * using date fns * using date fns * using date fns * using date fns * using date fns * removed moment * removed last traces of moment
This commit is contained in:
parent
1435c08d33
commit
ab27950bcc
17 changed files with 81 additions and 44 deletions
|
@ -7,7 +7,6 @@
|
|||
"globals": {
|
||||
"firebase": "readonly",
|
||||
"$": "readonly",
|
||||
"moment": "readonly",
|
||||
"jQuery": "readonly",
|
||||
"html2canvas": "readonly",
|
||||
"ClipboardItem": "readonly",
|
||||
|
|
19
frontend/package-lock.json
generated
19
frontend/package-lock.json
generated
|
@ -15,6 +15,7 @@
|
|||
"chartjs-plugin-trendline": "^0.2.2",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"damerau-levenshtein": "1.0.8",
|
||||
"date-fns": "2.28.0",
|
||||
"firebase": "^8.4.2",
|
||||
"howler": "^2.2.1",
|
||||
"node-object-hash": "2.3.10",
|
||||
|
@ -46,7 +47,6 @@
|
|||
"gulp-typescript": "^6.0.0-alpha.1",
|
||||
"html2canvas": "^1.4.1",
|
||||
"madge": "5.0.1",
|
||||
"moment": "^2.29.1",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"ts-loader": "9.2.6",
|
||||
"tsify": "^5.0.4",
|
||||
|
@ -4060,6 +4060,18 @@
|
|||
"node": ">=8.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/date-fns": {
|
||||
"version": "2.28.0",
|
||||
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.28.0.tgz",
|
||||
"integrity": "sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==",
|
||||
"engines": {
|
||||
"node": ">=0.11"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/date-fns"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.3.3",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz",
|
||||
|
@ -15139,6 +15151,11 @@
|
|||
"chokidar": ">=2.0.0 <4.0.0"
|
||||
}
|
||||
},
|
||||
"date-fns": {
|
||||
"version": "2.28.0",
|
||||
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.28.0.tgz",
|
||||
"integrity": "sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw=="
|
||||
},
|
||||
"debug": {
|
||||
"version": "4.3.3",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz",
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
"gulp-typescript": "^6.0.0-alpha.1",
|
||||
"html2canvas": "^1.4.1",
|
||||
"madge": "5.0.1",
|
||||
"moment": "^2.29.1",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"ts-loader": "9.2.6",
|
||||
"tsify": "^5.0.4",
|
||||
|
@ -57,6 +56,7 @@
|
|||
"chartjs-plugin-trendline": "^0.2.2",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"damerau-levenshtein": "1.0.8",
|
||||
"date-fns": "2.28.0",
|
||||
"firebase": "^8.4.2",
|
||||
"howler": "^2.2.1",
|
||||
"node-object-hash": "2.3.10",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as DB from "../db";
|
||||
import Config from "../config";
|
||||
import * as Misc from "../utils/misc";
|
||||
import { format } from "date-fns";
|
||||
|
||||
export function update(): void {
|
||||
$(".pageAccount .timePbTable tbody").html(`
|
||||
|
@ -85,11 +86,12 @@ export function update(): void {
|
|||
try {
|
||||
pbData = pb.time[15].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
dateText = `-<br><span class="sub">-</span>`;
|
||||
const date = new Date(pbData.timestamp);
|
||||
if (pbData.timestamp) {
|
||||
dateText =
|
||||
moment(pbData.timestamp).format("DD MMM YYYY") +
|
||||
format(date, "dd MMM yyyy") +
|
||||
"<br><div class='sub'>" +
|
||||
moment(pbData.timestamp).format("HH:mm") +
|
||||
format(date, "HH:mm") +
|
||||
"</div>";
|
||||
}
|
||||
text += `<tr>
|
||||
|
@ -113,11 +115,12 @@ export function update(): void {
|
|||
try {
|
||||
pbData = pb.time[30].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
dateText = `-<br><span class="sub">-</span>`;
|
||||
const date = new Date(pbData.timestamp);
|
||||
if (pbData.timestamp) {
|
||||
dateText =
|
||||
moment(pbData.timestamp).format("DD MMM YYYY") +
|
||||
format(date, "dd MMM yyyy") +
|
||||
"<br><div class='sub'>" +
|
||||
moment(pbData.timestamp).format("HH:mm") +
|
||||
format(date, "HH:mm") +
|
||||
"</div>";
|
||||
}
|
||||
text += `<tr>
|
||||
|
@ -141,11 +144,12 @@ export function update(): void {
|
|||
try {
|
||||
pbData = pb.time[60].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
dateText = `-<br><span class="sub">-</span>`;
|
||||
const date = new Date(pbData.timestamp);
|
||||
if (pbData.timestamp) {
|
||||
dateText =
|
||||
moment(pbData.timestamp).format("DD MMM YYYY") +
|
||||
format(date, "dd MMM yyyy") +
|
||||
"<br><div class='sub'>" +
|
||||
moment(pbData.timestamp).format("HH:mm") +
|
||||
format(date, "HH:mm") +
|
||||
"</div>";
|
||||
}
|
||||
text += `<tr>
|
||||
|
@ -169,11 +173,12 @@ export function update(): void {
|
|||
try {
|
||||
pbData = pb.time[120].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
dateText = `-<br><span class="sub">-</span>`;
|
||||
const date = new Date(pbData.timestamp);
|
||||
if (pbData.timestamp) {
|
||||
dateText =
|
||||
moment(pbData.timestamp).format("DD MMM YYYY") +
|
||||
format(date, "dd MMM yyyy") +
|
||||
"<br><div class='sub'>" +
|
||||
moment(pbData.timestamp).format("HH:mm") +
|
||||
format(date, "HH:mm") +
|
||||
"</div>";
|
||||
}
|
||||
text += `<tr>
|
||||
|
@ -200,11 +205,12 @@ export function update(): void {
|
|||
try {
|
||||
pbData = pb.words[10].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
dateText = `-<br><span class="sub">-</span>`;
|
||||
const date = new Date(pbData.timestamp);
|
||||
if (pbData.timestamp) {
|
||||
dateText =
|
||||
moment(pbData.timestamp).format("DD MMM YYYY") +
|
||||
format(date, "dd MMM yyyy") +
|
||||
"<br><div class='sub'>" +
|
||||
moment(pbData.timestamp).format("HH:mm") +
|
||||
format(date, "HH:mm") +
|
||||
"</div>";
|
||||
}
|
||||
text += `<tr>
|
||||
|
@ -228,11 +234,12 @@ export function update(): void {
|
|||
try {
|
||||
pbData = pb.words[25].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
dateText = `-<br><span class="sub">-</span>`;
|
||||
const date = new Date(pbData.timestamp);
|
||||
if (pbData.timestamp) {
|
||||
dateText =
|
||||
moment(pbData.timestamp).format("DD MMM YYYY") +
|
||||
format(date, "dd MMM yyyy") +
|
||||
"<br><div class='sub'>" +
|
||||
moment(pbData.timestamp).format("HH:mm") +
|
||||
format(date, "HH:mm") +
|
||||
"</div>";
|
||||
}
|
||||
text += `<tr>
|
||||
|
@ -256,11 +263,12 @@ export function update(): void {
|
|||
try {
|
||||
pbData = pb.words[50].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
dateText = `-<br><span class="sub">-</span>`;
|
||||
const date = new Date(pbData.timestamp);
|
||||
if (pbData.timestamp) {
|
||||
dateText =
|
||||
moment(pbData.timestamp).format("DD MMM YYYY") +
|
||||
format(date, "dd MMM yyyy") +
|
||||
"<br><div class='sub'>" +
|
||||
moment(pbData.timestamp).format("HH:mm") +
|
||||
format(date, "HH:mm") +
|
||||
"</div>";
|
||||
}
|
||||
text += `<tr>
|
||||
|
@ -284,11 +292,12 @@ export function update(): void {
|
|||
try {
|
||||
pbData = pb.words[100].sort((a, b) => b.wpm - a.wpm)[0];
|
||||
dateText = `-<br><span class="sub">-</span>`;
|
||||
const date = new Date(pbData.timestamp);
|
||||
if (pbData.timestamp) {
|
||||
dateText =
|
||||
moment(pbData.timestamp).format("DD MMM YYYY") +
|
||||
format(date, "dd MMM yyyy") +
|
||||
"<br><div class='sub'>" +
|
||||
moment(pbData.timestamp).format("HH:mm") +
|
||||
format(date, "HH:mm") +
|
||||
"</div>";
|
||||
}
|
||||
text += `<tr>
|
||||
|
|
|
@ -4,6 +4,7 @@ import * as ThemeColors from "../elements/theme-colors";
|
|||
import * as Misc from "../utils/misc";
|
||||
import Config from "../config";
|
||||
import * as ConfigEvent from "../observables/config-event";
|
||||
import { format } from "date-fns";
|
||||
|
||||
Chart.defaults.global.animation.duration = 250;
|
||||
|
||||
|
@ -244,7 +245,10 @@ export let accountHistory = new Chart($(".pageAccount #accountHistoryChart"), {
|
|||
"\n" +
|
||||
`language: ${resultData.language}` +
|
||||
"\n\n" +
|
||||
`date: ${moment(resultData.timestamp).format("DD MMM YYYY HH:mm")}`;
|
||||
`date: ${format(
|
||||
new Date(resultData.timestamp),
|
||||
"dd MMM yyyy HH:mm"
|
||||
)}`;
|
||||
|
||||
return label;
|
||||
},
|
||||
|
@ -356,7 +360,7 @@ export let accountActivity = new Chart(
|
|||
data.datasets[tooltipItem[0].datasetIndex].data[
|
||||
tooltipItem[0].index
|
||||
];
|
||||
return moment(resultData.x).format("DD MMM YYYY");
|
||||
return format(new Date(resultData.x), "dd MMM yyyy");
|
||||
},
|
||||
beforeLabel: function (tooltipItem, data) {
|
||||
let resultData =
|
||||
|
|
|
@ -3,6 +3,7 @@ import * as DB from "../db";
|
|||
import Config from "../config";
|
||||
import * as Misc from "../utils/misc";
|
||||
import * as Notifications from "./notifications";
|
||||
import { format } from "date-fns";
|
||||
|
||||
const currentLeaderboard = "time_15";
|
||||
|
||||
|
@ -120,6 +121,7 @@ function updateFooter(lb: LbKey): void {
|
|||
}
|
||||
if (currentRank[lb]) {
|
||||
const entry = currentRank[lb];
|
||||
const date = new Date(entry.timestamp);
|
||||
$(`#leaderboardsWrapper table.${side} tfoot`).html(`
|
||||
<tr>
|
||||
<td>${entry.rank}</td>
|
||||
|
@ -137,9 +139,8 @@ function updateFooter(lb: LbKey): void {
|
|||
: entry.consistency.toFixed(2) + "%"
|
||||
}</div></td>
|
||||
<td class="alignRight">time<br><div class="sub">${lb}</div></td>
|
||||
<td class="alignRight">${moment(entry.timestamp).format(
|
||||
"DD MMM YYYY"
|
||||
)}<br><div class='sub'>${moment(entry.timestamp).format("HH:mm")}</div></td>
|
||||
<td class="alignRight">${format(date, "dd MMM yyyy")}<br>
|
||||
<div class='sub'>${format(date, "HH:mm")}</div></td>
|
||||
</tr>
|
||||
`);
|
||||
}
|
||||
|
@ -216,6 +217,7 @@ function fillTable(lb: LbKey, prepend?: number): void {
|
|||
if (entry.name == loggedInUserName) {
|
||||
meClassString = ' class="me"';
|
||||
}
|
||||
const date = new Date(entry.timestamp);
|
||||
html += `
|
||||
<tr ${meClassString}>
|
||||
<td>${
|
||||
|
@ -235,9 +237,8 @@ function fillTable(lb: LbKey, prepend?: number): void {
|
|||
: entry.consistency.toFixed(2) + "%"
|
||||
}</div></td>
|
||||
<td class="alignRight">time<br><div class="sub">${lb}</div></td>
|
||||
<td class="alignRight">${moment(entry.timestamp).format(
|
||||
"DD MMM YYYY"
|
||||
)}<br><div class='sub'>${moment(entry.timestamp).format("HH:mm")}</div></td>
|
||||
<td class="alignRight">${format(date, "dd MMM yyyy")}<br>
|
||||
<div class='sub'>${format(date, "HH:mm")}</div></td>
|
||||
</tr>
|
||||
`;
|
||||
}
|
||||
|
|
1
frontend/src/scripts/modules.d.ts
vendored
1
frontend/src/scripts/modules.d.ts
vendored
|
@ -1,4 +1,3 @@
|
|||
declare let firebase: any; // typeof import("firebase").default;
|
||||
declare let moment: typeof import("moment");
|
||||
declare let grecaptcha: ReCaptchaV2.ReCaptcha;
|
||||
declare let html2canvas: typeof import("html2canvas").default;
|
||||
|
|
|
@ -14,6 +14,7 @@ import * as Notifications from "../elements/notifications";
|
|||
import Page from "./page";
|
||||
import * as Misc from "../utils/misc";
|
||||
import * as ActivePage from "../states/active-page";
|
||||
import { format } from "date-fns";
|
||||
|
||||
let filterDebug = false;
|
||||
//toggle filterdebug
|
||||
|
@ -149,6 +150,7 @@ function loadMoreLines(lineIndex?: number): void {
|
|||
charStats = result.correctChars + "/" + result.incorrectChars + "/-/-";
|
||||
}
|
||||
|
||||
const date = new Date(result.timestamp);
|
||||
$(".pageAccount .history table tbody").append(`
|
||||
<tr class="resultRow" id="result-${i}">
|
||||
<td>${pb}</td>
|
||||
|
@ -160,7 +162,9 @@ function loadMoreLines(lineIndex?: number): void {
|
|||
<td>${result.mode} ${result.mode2}</td>
|
||||
<td class="infoIcons">${icons}</td>
|
||||
<td>${tagIcons}</td>
|
||||
<td>${moment(result.timestamp).format("DD MMM YYYY<br>HH:mm")}</td>
|
||||
<td>${format(date, "dd MMM yyyy")}<br>
|
||||
${format(date, "HH:mm")}
|
||||
</td>
|
||||
</tr>`);
|
||||
}
|
||||
visibleTableLines = newVisibleLines;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Ape from "../ape";
|
||||
import * as Loader from "../elements/loader";
|
||||
import * as Notifications from "../elements/notifications";
|
||||
import { format } from "date-fns";
|
||||
|
||||
let apeKeys: MonkeyTypes.ApeKeys = {};
|
||||
|
||||
|
@ -43,12 +44,12 @@ function refreshList(): void {
|
|||
</div>
|
||||
</td>
|
||||
<td>${key.name}</td>
|
||||
<td>${moment(key.createdOn).format("DD MMM YYYY HH:mm")}</td>
|
||||
<td>${moment(key.modifiedOn).format("DD MMM YYYY HH:mm")}</td>
|
||||
<td>${format(new Date(key.createdOn), "dd MMM yyyy HH:mm")}</td>
|
||||
<td>${format(new Date(key.modifiedOn), "dd MMM yyyy HH:mm")}</td>
|
||||
<td>${
|
||||
key.lastUsedOn === -1
|
||||
? "-"
|
||||
: moment(key.lastUsedOn).format("DD MMM YYYY HH:mm")
|
||||
: format(new Date(key.lastUsedOn), "dd MMM yyyy HH:mm")
|
||||
}</td>
|
||||
<td>
|
||||
<div class="keyButtons">
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as DB from "../db";
|
||||
import { format } from "date-fns";
|
||||
|
||||
interface PersonalBest extends MonkeyTypes.PersonalBest {
|
||||
mode2: MonkeyTypes.Mode2<MonkeyTypes.Mode>;
|
||||
|
@ -40,11 +41,12 @@ function update(mode: MonkeyTypes.Mode): void {
|
|||
|
||||
list.forEach((pb) => {
|
||||
let dateText = `-<br><span class="sub">-</span>`;
|
||||
const date = new Date(pb.timestamp);
|
||||
if (pb.timestamp) {
|
||||
dateText =
|
||||
moment(pb.timestamp).format("DD MMM YYYY") +
|
||||
format(date, "DD MMM YYYY") +
|
||||
"<br><div class='sub'>" +
|
||||
moment(pb.timestamp).format("HH:mm") +
|
||||
format(date, "HH:mm") +
|
||||
"</div>";
|
||||
}
|
||||
$("#pbTablesPopup table tbody").append(`
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Ape from "../ape";
|
||||
import * as Loader from "../elements/loader";
|
||||
import * as Notifications from "../elements/notifications";
|
||||
import { format } from "date-fns";
|
||||
|
||||
type Quote = {
|
||||
_id: string;
|
||||
|
@ -32,7 +33,8 @@ function updateList(): void {
|
|||
quote.text.length < 60 ? "red" : ""
|
||||
}">Quote length: ${quote.text.length}</div>
|
||||
<div class="language">Language: ${quote.language}</div>
|
||||
<div class="timestamp">Submitted on: ${moment(quote.timestamp).format(
|
||||
<div class="timestamp">Submitted on: ${format(
|
||||
new Date(quote.timestamp),
|
||||
"DD MMM YYYY HH:mm"
|
||||
)}</div>
|
||||
</div>
|
||||
|
|
|
@ -11,6 +11,7 @@ import * as Replay from "./replay";
|
|||
import * as Misc from "../utils/misc";
|
||||
import * as SlowTimer from "../states/slow-timer";
|
||||
import * as ConfigEvent from "../observables/config-event";
|
||||
import { format } from "date-fns";
|
||||
|
||||
ConfigEvent.subscribe((eventKey, eventValue) => {
|
||||
if (eventValue === undefined || typeof eventValue !== "boolean") return;
|
||||
|
@ -220,16 +221,17 @@ export async function screenshot(): Promise<void> {
|
|||
revealReplay = true;
|
||||
Replay.pauseReplay();
|
||||
}
|
||||
const dateNow = new Date(Date.now());
|
||||
$("#resultReplay").addClass("hidden");
|
||||
$(".pageTest .ssWatermark").removeClass("hidden");
|
||||
$(".pageTest .ssWatermark").text(
|
||||
moment(Date.now()).format("DD MMM YYYY HH:mm") + " | monkeytype.com "
|
||||
format(dateNow, "dd MMM yyyy HH:mm") + " | monkeytype.com "
|
||||
);
|
||||
if (firebase.auth().currentUser != null) {
|
||||
$(".pageTest .ssWatermark").text(
|
||||
DB.getSnapshot().name +
|
||||
" | " +
|
||||
moment(Date.now()).format("DD MMM YYYY HH:mm") +
|
||||
format(dateNow, "dd MMM yyyy HH:mm") +
|
||||
" | monkeytype.com "
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as Loader from "../elements/loader";
|
||||
import { format } from "date-fns";
|
||||
|
||||
export function getuid(): void {
|
||||
console.error("Only share this uid with Miodec and nobody else!");
|
||||
|
@ -351,8 +352,9 @@ export async function getReleasesFromGitHub(): Promise<
|
|||
$("#versionHistory .releases").append(`
|
||||
<div class="release">
|
||||
<div class="title">${release.name}</div>
|
||||
<div class="date">${moment(release.published_at).format(
|
||||
"DD MMM YYYY"
|
||||
<div class="date">${format(
|
||||
new Date(release.published_at),
|
||||
"dd MMM yyyy"
|
||||
)}</div>
|
||||
<div class="body">${release.body.replace(/\r\n/g, "<br>")}</div>
|
||||
</div>
|
||||
|
|
|
@ -4972,7 +4972,6 @@
|
|||
<script src="js/jquery-3.5.1.min.js"></script>
|
||||
<script src="js/jquery.color.min.js"></script>
|
||||
<script src="js/easing.min.js"></script>
|
||||
<script src="js/moment.min.js"></script>
|
||||
<script src="js/html2canvas.min.js"></script>
|
||||
<script src="js/select2.min.js"></script>
|
||||
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
|
||||
|
|
2
frontend/static/js/moment.min.js
vendored
2
frontend/static/js/moment.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,6 @@
|
|||
"module": "ES6" /* Specify what module code is generated. */,
|
||||
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
||||
"types": [
|
||||
"moment",
|
||||
"jquery",
|
||||
"firebase",
|
||||
"select2"
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
"globals": {
|
||||
"firebase": "readonly",
|
||||
"$": "readonly",
|
||||
"moment": "readonly",
|
||||
"jQuery": "readonly",
|
||||
"html2canvas": "readonly",
|
||||
"ClipboardItem": "readonly",
|
||||
|
|
Loading…
Add table
Reference in a new issue