mirror of
https://github.com/SomboChea/ui
synced 2026-01-19 09:36:30 +07:00
refactor: replaced date fns with dayjs (#345)
This commit is contained in:
committed by
Juan Picado @jotadeveloper
parent
474e9e18de
commit
501845b5f8
@@ -104,7 +104,7 @@ const Package: React.FC<PackageInterface> = ({
|
||||
<OverviewItem>
|
||||
<Icon name="time" />
|
||||
<Published>{`Published on ${formatDate(time)} •`}</Published>
|
||||
{`${formatDateDistance(time)} ago`}
|
||||
{formatDateDistance(time)}
|
||||
</OverviewItem>
|
||||
);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ const UpLinks: React.FC = () => {
|
||||
<ListItem key={name}>
|
||||
<ListItemText>{name}</ListItemText>
|
||||
<Spacer />
|
||||
<ListItemText>{`${formatDateDistance(uplinks[name].fetched)} ago`}</ListItemText>
|
||||
<ListItemText>{formatDateDistance(uplinks[name].fetched)}</ListItemText>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
exports[`<UpLinks /> component should render the component when there is no uplink 1`] = `"<h6 class=\\"MuiTypography-root MuiTypography-subtitle1 MuiTypography-gutterBottom\\">verdaccio has no uplinks.</h6>"`;
|
||||
|
||||
exports[`<UpLinks /> component should render the component with uplinks 1`] = `"<h6 class=\\"MuiTypography-root css-5wp24z-StyledText e14i1sy10 MuiTypography-subtitle1\\">Uplinks</h6><ul class=\\"MuiList-root MuiList-padding\\"><li class=\\"MuiListItem-root MuiListItem-gutters\\"><div class=\\"MuiListItemText-root css-1pxn9ma-ListItemText e14i1sy12\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">npmjs</span></div><div class=\\"css-t1rp47-Spacer e14i1sy11\\"></div><div class=\\"MuiListItemText-root css-1pxn9ma-ListItemText e14i1sy12\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">over 1 year ago</span></div></li></ul>"`;
|
||||
exports[`<UpLinks /> component should render the component with uplinks 1`] = `"<h6 class=\\"MuiTypography-root css-5wp24z-StyledText e14i1sy10 MuiTypography-subtitle1\\">Uplinks</h6><ul class=\\"MuiList-root MuiList-padding\\"><li class=\\"MuiListItem-root MuiListItem-gutters\\"><div class=\\"MuiListItemText-root css-1pxn9ma-ListItemText e14i1sy12\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">npmjs</span></div><div class=\\"css-t1rp47-Spacer e14i1sy11\\"></div><div class=\\"MuiListItemText-root css-1pxn9ma-ListItemText e14i1sy12\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">a year ago</span></div></li></ul>"`;
|
||||
|
||||
@@ -25,7 +25,7 @@ const VersionsHistoryList: React.FC<Props> = ({ versions, packageName, time }) =
|
||||
<ListItemText>{version}</ListItemText>
|
||||
</StyledLink>
|
||||
<Spacer />
|
||||
<ListItemText>{time[version] ? `${formatDateDistance(time[version])} ago` : NOT_AVAILABLE}</ListItemText>
|
||||
<ListItemText>{time[version] ? formatDateDistance(time[version]) : NOT_AVAILABLE}</ListItemText>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
|
||||
@@ -71,7 +71,7 @@ describe('formatDateDistance', (): void => {
|
||||
const date2 = dateTwoMonthsAgo();
|
||||
// FIXME: we need to review this expect, fails every x time.
|
||||
// expect(formatDateDistance(date1)).toEqual('about 2 months');
|
||||
expect(formatDateDistance(date2)).toEqual('2 months');
|
||||
expect(formatDateDistance(date2)).toEqual('2 months ago');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -2,12 +2,15 @@ import { isObject } from 'util';
|
||||
|
||||
import { UpLinks } from '@verdaccio/types';
|
||||
import isString from 'lodash/isString';
|
||||
import format from 'date-fns/format';
|
||||
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
|
||||
import dayjs from 'dayjs';
|
||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||
|
||||
import { Time } from '../../types/packageMeta';
|
||||
|
||||
export const TIMEFORMAT = 'dd.MM.yyyy, HH:mm:ss';
|
||||
export const TIMEFORMAT = 'DD.MM.YYYY, HH:mm:ss';
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
/**
|
||||
* Formats license field for webui.
|
||||
@@ -52,11 +55,11 @@ export function formatRepository(repository: any): string | null {
|
||||
}
|
||||
|
||||
export function formatDate(lastUpdate: string | number): string {
|
||||
return format(new Date(lastUpdate), TIMEFORMAT);
|
||||
return dayjs(new Date(lastUpdate)).format('DD.MM.YYYY, HH:mm:ss');
|
||||
}
|
||||
|
||||
export function formatDateDistance(lastUpdate: Date | string | number): string {
|
||||
return formatDistanceToNow(new Date(lastUpdate));
|
||||
return dayjs(new Date(lastUpdate)).fromNow();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user