Skip to content

Commit

Permalink
fix(dateformat): update Props
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael2Gray committed Feb 11, 2022
1 parent e6069e4 commit d0b631d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
13 changes: 4 additions & 9 deletions src/components/date-format/date-format.component.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import React from 'react';
import { format } from 'date-fns';
import { format as formatFns } from 'date-fns';

type DateFormatProps = {
date: number | string | Date;
dateFormat: string;
dateTimeFormat?: string;
format: string;
};

export const DateFormat = ({
date,
dateFormat,
dateTimeFormat,
}: DateFormatProps) => (
<>{format(new Date(date), dateTimeFormat ? dateTimeFormat : dateFormat)}</>
export const DateFormat = ({ date, format }: DateFormatProps) => (
<>{formatFns(new Date(date), format)}</>
);
16 changes: 1 addition & 15 deletions src/components/date-format/date-format.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,8 @@ import { DateFormat } from './date-format.component';

describe('DateFormat', () => {
test('renders the date format', () => {
render(
<DateFormat date={new Date(2020, 0, 1)} dateFormat="E, d MMM yyyy" />
);
render(<DateFormat date={new Date(2020, 0, 1)} format="E, d MMM yyyy" />);

expect(screen.getByText('Wed, 1 Jan 2020')).toBeInTheDocument();
});

test('renders the date and time format', () => {
render(
<DateFormat
date={new Date(2020, 0, 1)}
dateFormat="E, d MMM yyyy"
dateTimeFormat="E, d MMM yyy HH:mm:ss"
/>
);

expect(screen.getByText('Wed, 1 Jan 2020 00:00:00')).toBeInTheDocument();
});
});

0 comments on commit d0b631d

Please sign in to comment.