diff --git a/package.json b/package.json index b958a9a9..e540b36b 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "core-js": "^3.32.1", "foundation-sites": "^6.4.3", "history": "^4.10.1", - "moment": "^2.29.4", "prop-types": "^15.8.1", "react-autocomplete": "1.8.1", "react-form": "^2.16.0", diff --git a/src/components/duration.tsx b/src/components/duration.tsx index 452e3414..d20237e4 100644 --- a/src/components/duration.tsx +++ b/src/components/duration.tsx @@ -1,20 +1,13 @@ -import * as moment from 'moment'; import * as React from 'react'; -export const Duration = (props: {durationMs: number, allowNewLines?: boolean}) => { - const momentTimeStart = moment.utc(0); - const momentTime = moment.utc(props.durationMs * 1000); - const duration = moment.duration(momentTime.diff(momentTimeStart)); - let formattedTime = ''; +import { formatDuration } from '../../v2'; - if (momentTime.diff(momentTimeStart, 'hours') === 0) { - formattedTime = ('0' + duration.minutes()).slice(-2) + ':' + ('0' + duration.seconds()).slice(-2) + ' min'; - } else { - if (momentTime.diff(momentTimeStart, 'days') > 0) { - formattedTime += momentTime.diff(momentTimeStart, 'days') + ' days' + (props.allowNewLines ? '
' : ' '); - } - - formattedTime += ('0' + duration.hours()).slice(-2) + ':' + ('0' + duration.minutes()).slice(-2) + ' hours'; - } - return ; -}; +/** + * Output a string duration from a number of seconds + * + * @param {number} props.durationS - The number of seconds. + * @param {number} props.durationMs - The number of seconds. DEPRECATED: The "Ms" suffix is incorrect, use props.durationS instead. + */ +export function Duration(props: {durationMs: number, durationS: number}) { + return {formatDuration(props.durationMs || props.durationS, 2)}; +} diff --git a/src/components/ticker.tsx b/src/components/ticker.tsx index 90bc7c2e..40fa6963 100644 --- a/src/components/ticker.tsx +++ b/src/components/ticker.tsx @@ -1,14 +1,13 @@ -import moment from 'moment'; import * as React from 'react'; import {interval, Subscription} from 'rxjs'; -export class Ticker extends React.Component<{intervalMs?: number, disabled?: boolean, children?: ((time: moment.Moment) => React.ReactNode)}, {time: moment.Moment}> { +export class Ticker extends React.Component<{intervalMs?: number, disabled?: boolean, children?: ((time: Date) => React.ReactNode)}, {time: Date}> { private subscription: Subscription | null = null; - constructor(props: {intervalMs?: number, children?: ((time: moment.Moment) => React.ReactNode)}) { + constructor(props: {intervalMs?: number, children?: ((time: Date) => React.ReactNode)}) { super(props); - this.state = { time: moment() }; + this.state = { time: new Date() }; this.ensureSubscribed(); } @@ -28,7 +27,7 @@ export class Ticker extends React.Component<{intervalMs?: number, disabled?: boo if (this.props.disabled) { this.ensureUnsubscribed(); } else if (!this.subscription) { - this.subscription = interval(this.props.intervalMs || 1000).subscribe(() => this.setState({ time: moment() })); + this.subscription = interval(this.props.intervalMs || 1000).subscribe(() => this.setState({ time: new Date() })); } } diff --git a/v2/utils/utils.tsx b/v2/utils/utils.tsx index 374f9375..c75d4f2a 100644 --- a/v2/utils/utils.tsx +++ b/v2/utils/utils.tsx @@ -1,4 +1,3 @@ -import moment from 'moment'; import * as React from 'react'; export interface Error { @@ -30,15 +29,6 @@ export function useData(getData: () => Promise, init?: T, callback?: (data return [data as T, loading, {state: error, retry: () => retry(!retrying)} as Error]; } -export function formatTimestamp(ts: string): string { - const inputFormat = 'YYYY-MM-DD HH:mm:ss Z z'; - const m = moment(ts, inputFormat); - if (!ts || !m.isValid()) { - return 'Never'; - } - return m.format('MMM D YYYY [at] hh:mm:ss'); -} - export const appendSuffixToClasses = (classNames: string, suffix: string): string => { const clString = classNames; const cl = (clString || '').split(' ') || []; diff --git a/yarn.lock b/yarn.lock index 970f1a2c..c7207320 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9988,11 +9988,6 @@ mkdirp@1.x, mkdirp@^1.0.3, mkdirp@^1.0.4: dependencies: minimist "^1.2.5" -moment@^2.29.4: - version "2.29.4" - resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108" - integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w== - moo@^0.5.0: version "0.5.1" resolved "https://registry.yarnpkg.com/moo/-/moo-0.5.1.tgz#7aae7f384b9b09f620b6abf6f74ebbcd1b65dbc4"