From 2cff8de933573922b7b240a2dcf24444f13ad1ef Mon Sep 17 00:00:00 2001
From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com>
Date: Sat, 22 Feb 2025 15:41:28 +0100
Subject: [PATCH 1/4] dep(twas): use JSR
---
frontend/deno.json | 2 +-
frontend/deno.lock | 8 ++++++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/frontend/deno.json b/frontend/deno.json
index 1a2fec1cb..ebedccbde 100644
--- a/frontend/deno.json
+++ b/frontend/deno.json
@@ -26,7 +26,7 @@
"@std/front-matter": "jsr:@std/front-matter@1",
"@std/semver": "jsr:@std/semver@1",
- "twas": "npm:twas@^2.1.3",
+ "@augustinmauroy/twas": "jsr:@augustinmauroy/twas@^1.0.0",
"$imagescript": "https://deno.land/x/imagescript@1.3.0/mod.ts",
"@deno/gfm": "jsr:@deno/gfm@0.10",
diff --git a/frontend/deno.lock b/frontend/deno.lock
index f587c6963..9cee63c8f 100644
--- a/frontend/deno.lock
+++ b/frontend/deno.lock
@@ -1,6 +1,7 @@
{
"version": "4",
"specifiers": {
+ "jsr:@augustinmauroy/twas@1": "1.0.0",
"jsr:@deno/gfm@0.10": "0.10.0",
"jsr:@denosaurs/emoji@0.3": "0.3.1",
"jsr:@fresh/core@^2.0.0-alpha.1": "2.0.0-alpha.25",
@@ -71,6 +72,9 @@
"npm:twas@^2.1.3": "2.1.3"
},
"jsr": {
+ "@augustinmauroy/twas@1.0.0": {
+ "integrity": "e6e464001c8865f9a23cbe06c7f3e0d4e44ff3701b050596e41d435546e4baa3"
+ },
"@deno/gfm@0.10.0": {
"integrity": "51708205e3559a4aeb6afb29d07c5bfafe7941f91bb360351ef6621de9a39527",
"dependencies": [
@@ -1872,6 +1876,7 @@
},
"workspace": {
"dependencies": [
+ "jsr:@augustinmauroy/twas@1",
"jsr:@deno/gfm@0.10",
"jsr:@fresh/core@^2.0.0-alpha.25",
"jsr:@fresh/plugin-tailwind@^0.0.1-alpha.7",
@@ -1890,8 +1895,7 @@
"npm:preact-render-to-string@6.3.1",
"npm:preact@10",
"npm:prismjs@^1.29.0",
- "npm:tailwindcss@3.4",
- "npm:twas@^2.1.3"
+ "npm:tailwindcss@3.4"
]
}
}
From efad61a8295574f996977cf131c43e0cbaf52c40 Mon Sep 17 00:00:00 2001
From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com>
Date: Tue, 11 Mar 2025 21:55:45 +0100
Subject: [PATCH 2/4] refracto: using intl api
---
frontend/deno.json | 1 -
frontend/deno.lock | 11 +---------
frontend/islands/admin/ScopeEdit.tsx | 4 ++--
frontend/islands/admin/UserEdit.tsx | 4 ++--
frontend/islands/new.tsx | 4 ++--
.../account/(_components)/AccountLayout.tsx | 4 ++--
frontend/routes/account/tokens/index.tsx | 14 ++++++------
frontend/routes/admin/publishingTasks.tsx | 6 ++---
.../package/(_components)/PackageHeader.tsx | 4 ++--
frontend/routes/package/og.ts | 4 ++--
frontend/routes/package/versions.tsx | 6 ++---
frontend/routes/status.tsx | 4 ++--
frontend/utils/timeAgo.ts | 22 +++++++++++++++++++
13 files changed, 50 insertions(+), 38 deletions(-)
create mode 100644 frontend/utils/timeAgo.ts
diff --git a/frontend/deno.json b/frontend/deno.json
index ebedccbde..bffefd6c9 100644
--- a/frontend/deno.json
+++ b/frontend/deno.json
@@ -26,7 +26,6 @@
"@std/front-matter": "jsr:@std/front-matter@1",
"@std/semver": "jsr:@std/semver@1",
- "@augustinmauroy/twas": "jsr:@augustinmauroy/twas@^1.0.0",
"$imagescript": "https://deno.land/x/imagescript@1.3.0/mod.ts",
"@deno/gfm": "jsr:@deno/gfm@0.10",
diff --git a/frontend/deno.lock b/frontend/deno.lock
index 9cee63c8f..4afabcef5 100644
--- a/frontend/deno.lock
+++ b/frontend/deno.lock
@@ -1,7 +1,6 @@
{
"version": "4",
"specifiers": {
- "jsr:@augustinmauroy/twas@1": "1.0.0",
"jsr:@deno/gfm@0.10": "0.10.0",
"jsr:@denosaurs/emoji@0.3": "0.3.1",
"jsr:@fresh/core@^2.0.0-alpha.1": "2.0.0-alpha.25",
@@ -68,13 +67,9 @@
"npm:prismjs@^1.29.0": "1.29.0",
"npm:sanitize-html@^2.13.0": "2.13.1",
"npm:tailwindcss@3.4": "3.4.14_postcss@8.4.47",
- "npm:tailwindcss@^3.4.1": "3.4.14_postcss@8.4.47",
- "npm:twas@^2.1.3": "2.1.3"
+ "npm:tailwindcss@^3.4.1": "3.4.14_postcss@8.4.47"
},
"jsr": {
- "@augustinmauroy/twas@1.0.0": {
- "integrity": "e6e464001c8865f9a23cbe06c7f3e0d4e44ff3701b050596e41d435546e4baa3"
- },
"@deno/gfm@0.10.0": {
"integrity": "51708205e3559a4aeb6afb29d07c5bfafe7941f91bb360351ef6621de9a39527",
"dependencies": [
@@ -1676,9 +1671,6 @@
"ts-interface-checker@0.1.13": {
"integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA=="
},
- "twas@2.1.3": {
- "integrity": "sha512-4Spnweu5OEBG9ZZIfabEh0js2x1p+34QsLLz+vHjER/nQX0L/+b7H6gelZbT+Ewi2KVNHcBy5gGhib9DeVAqpA=="
- },
"undici-types@5.26.5": {
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
},
@@ -1876,7 +1868,6 @@
},
"workspace": {
"dependencies": [
- "jsr:@augustinmauroy/twas@1",
"jsr:@deno/gfm@0.10",
"jsr:@fresh/core@^2.0.0-alpha.25",
"jsr:@fresh/plugin-tailwind@^0.0.1-alpha.7",
diff --git a/frontend/islands/admin/ScopeEdit.tsx b/frontend/islands/admin/ScopeEdit.tsx
index b7c239658..2cb963eda 100644
--- a/frontend/islands/admin/ScopeEdit.tsx
+++ b/frontend/islands/admin/ScopeEdit.tsx
@@ -1,7 +1,7 @@
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
import type { FullScope } from "../../utils/api_types.ts";
import { useState } from "preact/hooks";
-import twas from "twas";
+import { timeAgo } from "../../utils/timeAgo.ts";
import { api, path } from "../../utils/api.ts";
import { TableData, TableRow } from "../../components/Table.tsx";
@@ -71,7 +71,7 @@ export default function AdminScopeEdit({ scope }: { scope: FullScope }) {
: publishAttemptsPerWeekLimit}
{pkg.value.description || No description}
- Created {twas(new Date(pkg.value.createdAt).getTime())}. + Created {timeAgo(pkg.value.createdAt)}.
{fromCli && (diff --git a/frontend/routes/account/(_components)/AccountLayout.tsx b/frontend/routes/account/(_components)/AccountLayout.tsx index 3248c2fe8..ab6c93cd8 100644 --- a/frontend/routes/account/(_components)/AccountLayout.tsx +++ b/frontend/routes/account/(_components)/AccountLayout.tsx @@ -1,6 +1,6 @@ // Copyright 2024 the JSR authors. All rights reserved. MIT license. import { ComponentChildren } from "preact"; -import twas from "twas"; +import { timeAgo } from "../../../utils/timeAgo.ts"; import { AccountNav, AccountNavTab } from "./AccountNav.tsx"; import { FullUser, User } from "../../../utils/api_types.ts"; import { GitHubUserLink } from "../../../islands/GithubUserLink.tsx"; @@ -25,7 +25,7 @@ export function AccountLayout({ user, active, children }: AccountLayoutProps) { {user.name}
- Created account {twas(new Date(user.createdAt).getTime())} + Created account {timeAgo(new Date(user.createdAt).getTime())}
- Created {twas(new Date(token.createdAt).getTime())} + Created {timeAgo(new Date(token.createdAt).getTime())}
@@ -160,7 +160,7 @@ function SessionRow({ token }: { token: Token }) { Active {expiresAt === null ? "forever" : `– expires ${ - twas(new Date().getTime(), expiresAt.getTime()).replace( + timeAgo(expiresAt.getTime()).replace( "ago", "from now", ) @@ -169,7 +169,7 @@ function SessionRow({ token }: { token: Token }) { ) : ( - Inactive - expired {twas(expiresAt.getTime())} + Inactive - expired {timeAgo(expiresAt.getTime())} )} @@ -178,7 +178,7 @@ function SessionRow({ token }: { token: Token }) {
- Created {twas(new Date(token.createdAt).getTime())} + Created {timeAgo(new Date(token.createdAt).getTime())}
Created:{" "} - {twas(new Date(data.publishingTask.createdAt).getTime())} + {timeAgo(new Date(data.publishingTask.createdAt))}
{data.publishingTask.userId && (diff --git a/frontend/utils/timeAgo.ts b/frontend/utils/timeAgo.ts new file mode 100644 index 000000000..6f439d984 --- /dev/null +++ b/frontend/utils/timeAgo.ts @@ -0,0 +1,22 @@ +export function timeAgo(date: Date | string): string { + const now = new Date(); + const past = new Date(date); + const diff = Math.abs(now.getTime() - past.getTime()); + + const duration = { + years: Math.floor(diff / (1000 * 60 * 60 * 24 * 365)), + months: Math.floor( + (diff % (1000 * 60 * 60 * 24 * 365)) / (1000 * 60 * 60 * 24 * 30), + ), + days: Math.floor( + (diff % (1000 * 60 * 60 * 24 * 30)) / (1000 * 60 * 60 * 24), + ), + hours: Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)), + minutes: Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)), + seconds: Math.floor((diff % (1000 * 60)) / 1000), + }; + + // Force english because JSR is an English-only project + const formatter = new Intl.DurationFormat("en", { style: "long" }); + return formatter.format(duration); +} From 3721c6ee5c1d2187955010f6483afb1e8622e3b3 Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Tue, 11 Mar 2025 21:57:05 +0100 Subject: [PATCH 3/4] fix: ci --- frontend/islands/admin/UserEdit.tsx | 2 +- .../routes/account/(_components)/AccountLayout.tsx | 2 +- frontend/routes/account/tokens/index.tsx | 12 ++++++------ frontend/routes/admin/publishingTasks.tsx | 4 ++-- frontend/routes/package/og.ts | 2 +- frontend/routes/package/versions.tsx | 5 ++--- frontend/utils/timeAgo.ts | 2 ++ 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/frontend/islands/admin/UserEdit.tsx b/frontend/islands/admin/UserEdit.tsx index b239397a8..cd1447a8c 100644 --- a/frontend/islands/admin/UserEdit.tsx +++ b/frontend/islands/admin/UserEdit.tsx @@ -68,7 +68,7 @@ export default function UserEdit({ user }: { user: FullUser }) { : String(isBlocked)}
- Created account {timeAgo(new Date(user.createdAt).getTime())} + Created account {timeAgo(new Date(user.createdAt))}
- Created {timeAgo(new Date(token.createdAt).getTime())} + Created {timeAgo(new Date(token.createdAt))}
@@ -160,7 +160,7 @@ function SessionRow({ token }: { token: Token }) { Active {expiresAt === null ? "forever" : `– expires ${ - timeAgo(expiresAt.getTime()).replace( + timeAgo(expiresAt).replace( "ago", "from now", ) @@ -169,7 +169,7 @@ function SessionRow({ token }: { token: Token }) { ) : ( - Inactive - expired {timeAgo(expiresAt.getTime())} + Inactive - expired {timeAgo(expiresAt)} )} @@ -178,7 +178,7 @@ function SessionRow({ token }: { token: Token }) {
- Created {timeAgo(new Date(token.createdAt).getTime())} + Created {timeAgo(new Date(token.createdAt))}