|
1 | 1 | import moment from 'moment'; |
2 | 2 | import { CustomTooltip } from '../custom'; |
3 | 3 |
|
| 4 | +/** |
| 5 | + * Returns the relative time (e.g. "2 hours ago") from a given date string |
| 6 | + * @param {string} date - ISO format date string |
| 7 | + * @returns {string} Human-readable relative time |
| 8 | + */ |
4 | 9 | export const getRelativeTime = (date: string): string => { |
5 | 10 | return moment(date).fromNow(); |
6 | 11 | }; |
7 | 12 |
|
| 13 | +/** |
| 14 | + * Returns a fully formatted date and time string |
| 15 | + * @param {string} date - ISO format date string |
| 16 | + * @returns {string} Formatted date in "ddd, MMM D, YYYY h:mm A" format (e.g. "Mon, Jan 1, 2025 3:45 PM") |
| 17 | + */ |
8 | 18 | export const getFullFormattedTime = (date: string): string => { |
9 | 19 | return moment(date).format('ddd, MMM D, YYYY h:mm A'); |
10 | 20 | }; |
11 | 21 |
|
| 22 | +/** |
| 23 | + * Formats a date string into a short date format |
| 24 | + * @param {string} date - ISO format date string |
| 25 | + * @returns {string} Formatted date in "Month Day, Year" format (e.g. "Jan 1, 2025") |
| 26 | + */ |
12 | 27 | export const getFormatDate = (date: string) => { |
13 | 28 | const options = { year: 'numeric' as const, month: 'short' as const, day: 'numeric' as const }; |
14 | 29 | const formattedDate = new Date(date).toLocaleDateString('en-US', options); |
15 | 30 | return formattedDate; |
16 | 31 | }; |
17 | 32 |
|
| 33 | +/** |
| 34 | + * React component that displays relative time with a tooltip showing the full date and time |
| 35 | + * @param {Object} props - Component props |
| 36 | + * @param {string} props.date - ISO format date string |
| 37 | + * @returns {JSX.Element} Formatted time component with tooltip |
| 38 | + */ |
18 | 39 | export const FormattedTime = ({ date }: { date: string }) => { |
19 | 40 | return ( |
20 | 41 | <CustomTooltip title={getFullFormattedTime(date)} disableInteractive> |
|
0 commit comments