Skip to content

Commit

Permalink
Update CONTRIBUTING.md
Browse files Browse the repository at this point in the history
  • Loading branch information
koolamusic committed Nov 4, 2023
1 parent aec989a commit 9618a89
Showing 1 changed file with 0 additions and 76 deletions.
76 changes: 0 additions & 76 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,6 @@

WIP

```tsx
// DateComponent.tsx
import * as React from 'react';
import { differenceInSeconds, isSameYear, isToday } from 'date-fns';
import {
FormattedDate,
FormattedMessage,
FormattedRelativeTime,
FormattedTime,
} from 'react-intl';

export interface RelativeTimeProps {
date: Date;
numeric?: 'auto' | 'always';
style?: 'long' | 'short' | 'narrow';
}

export const RelativeTime: React.FC<RelativeTimeProps> = (props) => {
const { date, numeric = 'auto', style = 'short' } = props;

const diff = React.useMemo(
() => differenceInSeconds(new Date(date), new Date()),
[props.date],
);

if (diff < 0 && diff > -60) {
return <FormattedMessage id="timeAgo" defaultMessage="Just now" />;
}

return (
<>
<FormattedRelativeTime
value={diff}
updateIntervalInSeconds={60}
style={style}
numeric={numeric}
/>
</>
);
};

export interface DateTimeProps {
date: Date;
style?: 'long' | 'short' | 'narrow';
}

export const DateTime: React.FC<DateTimeProps> = (props) => {
const { date, style = 'long' } = props;

const now = new Date();

const isLong = style === 'long';
const sameDay = isToday(date);
const sameYear = isSameYear(date, now);

let year: 'numeric' | undefined = undefined;
if (!sameYear) {
year = 'numeric';
}

const formattedDate =
isLong || (!isLong && !sameDay) ? (
<FormattedDate value={date} day="numeric" month="long" year={year} />
) : null;
const formattedTime =
isLong || sameDay ? <FormattedTime value={date} /> : null;

return (
<>
{formattedDate}
{formattedDate && formattedTime && ', '}
{formattedTime}
</>
);
};
```

## Team

Expand Down

0 comments on commit 9618a89

Please sign in to comment.