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

refactor(deps)!: remove moment dep and usage #535

Merged
merged 4 commits into from
Aug 22, 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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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",
Expand Down
27 changes: 10 additions & 17 deletions src/components/duration.tsx
Original file line number Diff line number Diff line change
@@ -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 ? '<br>' : ' ');
}

formattedTime += ('0' + duration.hours()).slice(-2) + ':' + ('0' + duration.minutes()).slice(-2) + ' hours';
}
return <span dangerouslySetInnerHTML={{__html: formattedTime}}/>;
};
/**
* 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 <span>{formatDuration(props.durationMs || props.durationS, 2)}</span>;
}
9 changes: 4 additions & 5 deletions src/components/ticker.tsx
Original file line number Diff line number Diff line change
@@ -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();
}

Expand All @@ -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() }));
}
}

Expand Down
10 changes: 0 additions & 10 deletions v2/utils/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import moment from 'moment';
import * as React from 'react';

export interface Error {
Expand Down Expand Up @@ -30,15 +29,6 @@ export function useData<T>(getData: () => Promise<T>, 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(' ') || [];
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13041,11 +13041,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"
Expand Down