-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
41 lines (38 loc) · 1.24 KB
/
utils.ts
File metadata and controls
41 lines (38 loc) · 1.24 KB
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
37
38
39
40
41
export const dateParseragGrid = (params: any) => {
try {
if (params.newValue instanceof Date) {
return params.newValue;
}
return stringToDate(params.newValue, 'dd/mm/yyyy', '/');
} catch (ex) {
console.error(`Error parsing the date value: ${params.newValue} and node : `, params.node);
return null;
}
};
export const shortDateFormatteragGrid = (params: any): any => {
try {
if (params.value) {
return shortDateFormatter.format(params.value);
}
} catch (ex) {
console.error(`Error formatting the date for value: ${params.value} and node : `, params.node);
}
return null;
};
const stringToDate = (date: any, format: any, delimiter: any) => {
const formatLowerCase = format.toLowerCase();
const formatItems = formatLowerCase.split(delimiter);
const dateItems = date.split(delimiter);
const monthIndex = formatItems.indexOf('mm');
const dayIndex = formatItems.indexOf('dd');
const yearIndex = formatItems.indexOf('yyyy');
let month = parseInt(dateItems[monthIndex], 10);
month -= 1;
const formatedDate = new Date(
parseInt(dateItems[yearIndex], 10),
month,
parseInt(dateItems[dayIndex], 10)
);
return formatedDate;
};
const shortDateFormatter = new Intl.DateTimeFormat('en-GB');