Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate from moment to date-fns #988

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions warpgate-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@typescript-eslint/parser": "^7.13.0",
"bootstrap": "^5.3.3",
"copy-text-to-clipboard": "^3.0.1",
"date-fns": "^3.6.0",
"eslint": "^8.57.0",
"eslint-config-standard": "^17.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
Expand All @@ -42,7 +43,6 @@
"eslint-plugin-promise": "^6.2.0",
"eslint-plugin-svelte": "^2.39.4",
"format-duration": "^3.0.2",
"moment": "^2.29.4",
"otplib": "^12.0.1",
"qrcode": "^1.5.1",
"sass": "^1.77.6",
Expand All @@ -64,4 +64,4 @@
"xterm": "^4.18.0",
"xterm-addon-serialize": "^0.7.0"
}
}
}
4 changes: 2 additions & 2 deletions warpgate-web/src/admin/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { onDestroy } from 'svelte'
import { link } from 'svelte-spa-router'
import { api, SessionSnapshot } from 'admin/lib/api'
import moment from 'moment'
import { formatDistance } from 'date-fns';
import { timer, Observable, switchMap, from, combineLatest, fromEvent, merge } from 'rxjs'
import RelativeDate from './RelativeDate.svelte'
import AsyncButton from 'common/AsyncButton.svelte'
Expand Down Expand Up @@ -104,7 +104,7 @@

<div class="meta">
{#if session.ended }
{moment.duration(moment(session.ended).diff(session.started)).humanize()}
{formatDistance(new Date(session.started), new Date(session.ended))}
{/if}
</div>

Expand Down
6 changes: 3 additions & 3 deletions warpgate-web/src/admin/Session.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { api, SessionSnapshot, Recording, TargetSSHOptions, TargetHTTPOptions, T
import { timeAgo } from 'admin/lib/time'
import AsyncButton from 'common/AsyncButton.svelte'
import DelayedSpinner from 'common/DelayedSpinner.svelte'
import moment from 'moment'
import { formatDistance, formatDistanceToNow } from 'date-fns';
import { onDestroy } from 'svelte'
import { link } from 'svelte-spa-router'
import { Alert } from '@sveltestrap/sveltestrap'
Expand Down Expand Up @@ -79,9 +79,9 @@ onDestroy(() => clearInterval(interval))
</strong>
<span class="text-muted">
{#if session.ended}
{moment.duration(moment(session.ended).diff(session.started)).humanize()} long, <RelativeDate date={session.started} />
{formatDistance(new Date(session.started), new Date(session.ended))} long, <RelativeDate date={session.started} />
{:else}
{moment.duration(moment().diff(session.started)).humanize()}
{formatDistanceToNow(new Date(session.started))}
{/if}
</span>
</div>
Expand Down
6 changes: 3 additions & 3 deletions warpgate-web/src/admin/lib/time.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from 'moment'
import { formatDistanceToNow } from 'date-fns'

export function timeAgo (t: Date): string {
return moment(t).fromNow()
export function timeAgo(t: Date): string {
return formatDistanceToNow(t, { addSuffix: true })
}
Loading
Loading