forked from amand33p/bug-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperFuncs.ts
More file actions
36 lines (30 loc) · 828 Bytes
/
Copy pathhelperFuncs.ts
File metadata and controls
36 lines (30 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { format, formatDistanceToNowStrict } from 'date-fns';
interface ReturnedError {
response?: {
data?: {
message: string;
};
};
message: string;
}
export const getErrorMsg = (err: ReturnedError) => {
if (err?.response?.data?.message) {
return err.response.data.message;
} else {
return err.message;
}
};
export const truncateString = (text: string, maxCharLimit: number) => {
return text.length < maxCharLimit
? text
: text.slice(0, maxCharLimit) + '...';
};
export const formatDateTime = (date: Date) => {
return format(new Date(date), "dd/MM/yy',' h':'mm a");
};
export const formatDateInWords = (date: Date) => {
return format(new Date(date), "MMM d', ' YYY");
};
export const formatTimeAgo = (date: Date) => {
return formatDistanceToNowStrict(new Date(date));
};