-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.ts
More file actions
61 lines (46 loc) · 1.1 KB
/
utils.ts
File metadata and controls
61 lines (46 loc) · 1.1 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { format } from "date-fns";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export const getDateObect = (val) => {
let date;
if (!val) {
return null;
}
if (Object.prototype.toString.call(val) === "[object Date]") {
if (isNaN(val)) {
return null;
}
}
if (typeof val.toDate === "function") {
date = val.toDate();
} else {
date = new Date(val);
}
return date;
};
export const formatDate = (val, formatStr, locale) => {
if (!val) {
return "";
}
const date = getDateObect(val);
if (!date) {
return "";
}
const options = {};
// if (dateLocales[locale]) {
// options = { locale: dateLocales[locale] }
// }
return format(date, formatStr, options);
};
export const getYmd = (val, locale) => {
return formatDate(val, "yyyy-MM-dd", locale);
};
export const getDay = (val, locale) => {
return formatDate(val, "iiii", locale);
};
export const getDate = (val, locale) => {
return formatDate(val, "d MMM", locale);
};