Skip to content

Commit 27d4b4c

Browse files
feat(twas): refracto to use intl api
Co-Authored-By: Leo Kettmeir <[email protected]>
1 parent feb4a41 commit 27d4b4c

File tree

18 files changed

+89
-51
lines changed

18 files changed

+89
-51
lines changed

frontend/deno.json

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"@std/front-matter": "jsr:@std/front-matter@1",
2929
"@std/semver": "jsr:@std/semver@1",
3030

31-
"twas": "npm:twas@^2.1.3",
3231
"$imagescript": "https://deno.land/x/[email protected]/mod.ts",
3332

3433
"@deno/gfm": "jsr:@deno/[email protected]",

frontend/deno.lock

+2-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/islands/new.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
import { Package, Scope, User } from "../utils/api_types.ts";
99
import { api, path } from "../utils/api.ts";
1010
import { ComponentChildren } from "preact";
11-
import twas from "twas";
1211
import { TicketModal } from "./TicketModal.tsx";
12+
import { timeAgo } from "../utils/timeAgo.ts";
1313

1414
interface IconColorProps {
1515
done: Signal<unknown>;
@@ -463,7 +463,7 @@ export function CreatePackage({ scope, name, pkg, fromCli }: {
463463
</p>
464464
<p>{pkg.value.description || <i>No description</i>}</p>
465465
<p class="text-tertiary">
466-
Created {twas(new Date(pkg.value.createdAt).getTime())}.
466+
Created {timeAgo(pkg.value.createdAt)}.bc4 (feat(twas): refracto to use intl api)
467467
</p>
468468
{fromCli && (
469469
<p class="mt-2 text-tertiary">

frontend/routes/account/(_components)/AccountLayout.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
22
import { ComponentChildren } from "preact";
3-
import twas from "twas";
3+
import { timeAgo } from "../../../utils/timeAgo.ts";
44
import { AccountNav, AccountNavTab } from "./AccountNav.tsx";
55
import { FullUser, User } from "../../../utils/api_types.ts";
66
import { GitHubUserLink } from "../../../islands/GithubUserLink.tsx";
@@ -25,7 +25,7 @@ export function AccountLayout({ user, active, children }: AccountLayoutProps) {
2525
{user.name}
2626
</h1>
2727
<p class="text-xs text-secondary">
28-
Created account {twas(new Date(user.createdAt).getTime())}
28+
Created account {timeAgo(new Date(user.createdAt))}
2929
</p>
3030
<p class="text-base mt-2">
3131
<GitHubUserLink user={user} />

frontend/routes/account/tickets.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { define } from "../../util.ts";
55
import { Table, TableData, TableRow } from "../../components/Table.tsx";
66
import { Ticket } from "../../utils/api_types.ts";
77
import { path } from "../../utils/api.ts";
8-
import twas from "twas";
98
import { TbCheck, TbClock } from "tb-icons";
109
import { TicketTitle } from "../../components/TicketTitle.tsx";
10+
import { timeAgo } from "../../utils/timeAgo.ts";
1111

1212
export default define.page<typeof handler>(function AccountInvitesPage({
1313
data,
@@ -56,12 +56,12 @@ export default define.page<typeof handler>(function AccountInvitesPage({
5656
<TableData
5757
title={new Date(ticket.createdAt).toISOString().slice(0, 10)}
5858
>
59-
{twas(new Date(ticket.createdAt).getTime())}
59+
{timeAgo(ticket.createdAt)}
6060
</TableData>
6161
<TableData
6262
title={new Date(ticket.updatedAt).toISOString().slice(0, 10)}
6363
>
64-
{twas(new Date(ticket.updatedAt).getTime())}
64+
{timeAgo(ticket.updatedAt)}
6565
</TableData>
6666
<TableData>
6767
<a class="button-primary" href={`/ticket/${ticket.id}`}>view</a>

frontend/routes/account/tokens/index.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { define } from "../../../util.ts";
55
import { path } from "../../../utils/api.ts";
66
import { Token } from "../../../utils/api_types.ts";
77
import { AccountLayout } from "../(_components)/AccountLayout.tsx";
8-
import twas from "twas";
8+
import { timeAgo } from "../../../utils/timeAgo.ts";
99
import { RevokeToken } from "./(_islands)/RevokeToken.tsx";
1010
import TbPlus from "tb-icons/TbPlus";
1111

@@ -105,7 +105,7 @@ function PersonalTokenRow({ token }: { token: Token }) {
105105
<b>Active</b> {expiresAt === null
106106
? "forever"
107107
: `– expires ${
108-
twas(new Date().getTime(), expiresAt.getTime()).replace(
108+
timeAgo(expiresAt).replace(
109109
"ago",
110110
"from now",
111111
)
@@ -114,12 +114,12 @@ function PersonalTokenRow({ token }: { token: Token }) {
114114
)
115115
: (
116116
<span class="text-red-600">
117-
<b>Inactive</b> - expired {twas(expiresAt.getTime())}
117+
<b>Inactive</b> - expired {timeAgo(expiresAt)}
118118
</span>
119119
)}
120120
</p>
121121
<p class="text-sm sm:text-right">
122-
Created {twas(new Date(token.createdAt).getTime())}
122+
Created {timeAgo(new Date(token.createdAt))}
123123
</p>
124124
</div>
125125
<p class="text-sm text-secondary">
@@ -160,7 +160,7 @@ function SessionRow({ token }: { token: Token }) {
160160
<b>Active</b> {expiresAt === null
161161
? "forever"
162162
: `– expires ${
163-
twas(new Date().getTime(), expiresAt.getTime()).replace(
163+
timeAgo(expiresAt).replace(
164164
"ago",
165165
"from now",
166166
)
@@ -169,7 +169,7 @@ function SessionRow({ token }: { token: Token }) {
169169
)
170170
: (
171171
<span class="text-red-600 dark:text-red-500">
172-
<b>Inactive</b> - expired {twas(expiresAt.getTime())}
172+
<b>Inactive</b> - expired {timeAgo(expiresAt)}
173173
</span>
174174
)}
175175

@@ -178,7 +178,7 @@ function SessionRow({ token }: { token: Token }) {
178178
</div>
179179
<div>
180180
<p class="text-sm sm:text-right">
181-
Created {twas(new Date(token.createdAt).getTime())}
181+
Created {timeAgo(new Date(token.createdAt))}
182182
</p>
183183
</div>
184184
</div>

frontend/routes/admin/audit.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AuditLog, List } from "../../utils/api_types.ts";
55
import { AdminNav } from "./(_components)/AdminNav.tsx";
66
import { AuditURLQuerySearch } from "./(_islands)/AuditURLQuerySearch.tsx";
77
import { define } from "../../util.ts";
8-
import twas from "twas";
8+
import { timeAgo } from "../../utils/timeAgo.ts";
99

1010
export default define.page<typeof handler>(function Users({ data, url }) {
1111
return (
@@ -60,7 +60,7 @@ export default define.page<typeof handler>(function Users({ data, url }) {
6060
)}
6161
align="right"
6262
>
63-
{twas(new Date(log.createdAt).getTime())}
63+
{timeAgo(log.createdAt)}
6464
</TableData>
6565
</TableRow>
6666
))}

frontend/routes/admin/packages.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { List, Package } from "../../utils/api_types.ts";
55
import { AdminNav } from "./(_components)/AdminNav.tsx";
66
import { URLQuerySearch } from "./(_components)/URLQuerySearch.tsx";
77
import { define } from "../../util.ts";
8-
import twas from "twas";
8+
import { timeAgo } from "../../utils/timeAgo.ts";
99
import { CopyButton } from "./(_islands)/CopyButton.tsx";
1010

1111
export default define.page<typeof handler>(function Packages({ data, url }) {
@@ -82,19 +82,19 @@ export default define.page<typeof handler>(function Packages({ data, url }) {
8282
? new Date(pkg.whenFeatured).toISOString().slice(0, 10)
8383
: ""}
8484
>
85-
{pkg.whenFeatured && twas(new Date(pkg.whenFeatured).getTime())}
85+
{pkg.whenFeatured && timeAgo(pkg.whenFeatured)}
8686
</TableData>
8787
<TableData
8888
title={new Date(pkg.updatedAt).toISOString().slice(0, 10)}
8989
align="right"
9090
>
91-
{twas(new Date(pkg.updatedAt).getTime())}
91+
{timeAgo(pkg.updatedAt)}
9292
</TableData>
9393
<TableData
9494
title={new Date(pkg.createdAt).toISOString().slice(0, 10)}
9595
align="right"
9696
>
97-
{twas(new Date(pkg.createdAt).getTime())}
97+
{timeAgo(pkg.createdAt)}
9898
</TableData>
9999
</TableRow>
100100
))}

frontend/routes/admin/publishingTasks.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AdminNav } from "./(_components)/AdminNav.tsx";
55
import { path } from "../../utils/api.ts";
66
import { List, PublishingTask } from "../../utils/api_types.ts";
77
import { URLQuerySearch } from "./(_components)/URLQuerySearch.tsx";
8-
import twas from "twas";
8+
import { timeAgo } from "../../utils/timeAgo.ts";
99
import PublishingTaskRequeue from "../../islands/PublishingTaskRequeue.tsx";
1010
import { CopyButton } from "./(_islands)/CopyButton.tsx";
1111

@@ -110,14 +110,22 @@ export default define.page<typeof handler>(function PublishingTasks({
110110
{publishingTask.packageVersion}
111111
</a>
112112
</TableData>
113+
<TableData
114+
title={new Date(publishingTask.createdAt).toISOString().slice(
115+
0,
116+
10,
117+
)}
118+
>
119+
{timeAgo(publishingTask.createdAt)}
120+
</TableData>
113121
<TableData
114122
title={new Date(publishingTask.updatedAt).toISOString().slice(
115123
0,
116124
10,
117125
)}
118126
align="right"
119127
>
120-
{twas(new Date(publishingTask.updatedAt).getTime())}
128+
{timeAgo(publishingTask.updatedAt)}
121129
</TableData>
122130
<TableData
123131
title={new Date(publishingTask.createdAt).toISOString().slice(
@@ -126,7 +134,7 @@ export default define.page<typeof handler>(function PublishingTasks({
126134
)}
127135
align="right"
128136
>
129-
{twas(new Date(publishingTask.createdAt).getTime())}
137+
{timeAgo(publishingTask.createdAt)}
130138
</TableData>
131139
<TableData>
132140
<PublishingTaskRequeue publishingTask={publishingTask} />

frontend/routes/admin/scopes/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { AdminNav } from "../(_components)/AdminNav.tsx";
66
import { URLQuerySearch } from "../(_components)/URLQuerySearch.tsx";
77
import { define } from "../../../util.ts";
88
import TbArrowRight from "tb-icons/TbArrowRight";
9-
import twas from "twas";
109
import { CopyButton } from "../(_islands)/CopyButton.tsx";
1110
import { EditModal } from "../(_islands)/EditModal.tsx";
11+
import { timeAgo } from "../../../utils/timeAgo.ts";
1212

1313
export default define.page<typeof handler>(function Scopes({ data, url }) {
1414
return (
@@ -85,7 +85,7 @@ export default define.page<typeof handler>(function Scopes({ data, url }) {
8585
title={new Date(scope.createdAt).toISOString().slice(0, 10)}
8686
align="right"
8787
>
88-
{twas(new Date(scope.createdAt).getTime())}
88+
{timeAgo(scope.createdAt)}
8989
</TableData>
9090
<TableData align="right">
9191
<EditModal

frontend/routes/admin/tickets.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { AdminNav } from "./(_components)/AdminNav.tsx";
55
import { path } from "../../utils/api.ts";
66
import { List, Ticket } from "../../utils/api_types.ts";
77
import { URLQuerySearch } from "./(_components)/URLQuerySearch.tsx";
8-
import twas from "twas";
98
import { TbCheck, TbClock } from "tb-icons";
9+
import { timeAgo } from "../../utils/timeAgo.ts";
1010

1111
export default define.page<typeof handler>(function Tickets({
1212
data,
@@ -88,7 +88,7 @@ export default define.page<typeof handler>(function Tickets({
8888
)}
8989
align="right"
9090
>
91-
{twas(new Date(ticket.updatedAt).getTime())}
91+
{timeAgo(ticket.updatedAt)}
9292
</TableData>
9393
<TableData
9494
title={new Date(ticket.createdAt).toISOString().slice(
@@ -97,9 +97,9 @@ export default define.page<typeof handler>(function Tickets({
9797
)}
9898
align="right"
9999
>
100-
{twas(new Date(ticket.createdAt).getTime())}
100+
{timeAgo(ticket.createdAt)}
101101
</TableData>
102-
<TableData align="right">
102+
<TableData align="right"></TableData>
103103
<a class="button-primary" href={`/ticket/${ticket.id}`}>view</a>
104104
</TableData>
105105
</TableRow>

frontend/routes/admin/users.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { FullUser, List } from "../../utils/api_types.ts";
55
import { AdminNav } from "./(_components)/AdminNav.tsx";
66
import { URLQuerySearch } from "./(_components)/URLQuerySearch.tsx";
77
import { define } from "../../util.ts";
8-
import twas from "twas";
98
import { CopyButton } from "./(_islands)/CopyButton.tsx";
109
import { EditModal } from "./(_islands)/EditModal.tsx";
10+
import { timeAgo } from "../../utils/timeAgo.ts";
1111

1212
export default define.page<typeof handler>(function Users({ data, url }) {
1313
return (
@@ -62,7 +62,7 @@ export default define.page<typeof handler>(function Users({ data, url }) {
6262
title={new Date(user.createdAt).toISOString().slice(0, 10)}
6363
align="right"
6464
>
65-
{twas(new Date(user.createdAt).getTime())}
65+
{timeAgo(user.createdAt)}
6666
</TableData>
6767
<TableData align="right">
6868
<EditModal

frontend/routes/package/(_components)/PackageHeader.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
TbRosetteDiscountCheck,
1414
} from "tb-icons";
1515
import { Tooltip } from "../../../components/Tooltip.tsx";
16-
import twas from "twas";
16+
import { timeAgo } from "../../../utils/timeAgo.ts";
1717
import { greaterThan, parse } from "@std/semver";
1818
import { DownloadWidget } from "../(_islands)/DownloadWidget.tsx";
1919

@@ -214,7 +214,7 @@ export function PackageHeader({
214214
)}
215215
>
216216
{`${
217-
twas(new Date(selectedVersion.createdAt).getTime())
217+
timeAgo(new Date(selectedVersion.createdAt))
218218
} (${selectedVersion.version})`}
219219
</div>
220220
</div>

frontend/routes/package/og.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { HttpError, RouteConfig } from "fresh";
44
import { Image } from "$imagescript";
5-
import twas from "twas";
5+
import { timeAgo } from "../../utils/timeAgo.ts";
66

77
import { packageDataWithVersion } from "../../utils/data.ts";
88
import { define } from "../../util.ts";
@@ -263,7 +263,7 @@ export const handler = define.handlers({
263263
const publishDateText = Image.renderText(
264264
dmmonoFont,
265265
25,
266-
twas(new Date(selectedVersion.createdAt).getTime()),
266+
timeAgo(new Date(selectedVersion.createdAt)),
267267
COLOR_GRAY,
268268
);
269269
const result = new Image(

frontend/routes/package/versions.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
} from "../../utils/api_types.ts";
88
import { define } from "../../util.ts";
99
import { compare, equals, format, lessThan, parse, SemVer } from "@std/semver";
10-
import twas from "twas";
10+
import { timeAgo } from "../../utils/timeAgo.ts";
1111
import { packageData } from "../../utils/data.ts";
1212
import { PackageHeader } from "./(_components)/PackageHeader.tsx";
1313
import { PackageNav, Params } from "./(_components)/PackageNav.tsx";
@@ -250,7 +250,7 @@ function Version({
250250
{" "}
251251
</>
252252
)}
253-
{twas(new Date(version.createdAt).getTime())}
253+
{timeAgo(new Date(version.createdAt))}
254254
</div>
255255
)}
256256
</div>
@@ -292,8 +292,7 @@ function Version({
292292
: <TbClockHour3 class="size-4 stroke-blue-500 stroke-2" />}
293293
<span>
294294
{ordinalNumber(tasks.length - i)} publishing attempt{" "}
295-
{statusVerb[task.status]}{" "}
296-
{twas(new Date(task.updatedAt).getTime())}
295+
{statusVerb[task.status]} {timeAgo(task.updatedAt)}
297296
</span>
298297
<a href={`/status/${task.id}`} class="link justify-self-end z-20">
299298
Details

0 commit comments

Comments
 (0)