1
+ import { type ClassValue , clsx } from "clsx" ;
2
+ import { twMerge } from "tailwind-merge" ;
3
+
4
+ export function cn ( ...inputs : ClassValue [ ] ) {
5
+ return twMerge ( clsx ( inputs ) ) ;
6
+ }
7
+
8
+ export const parseStringify = ( value : any ) => JSON . parse ( JSON . stringify ( value ) ) ;
9
+
10
+ export const convertFileToUrl = ( file : File ) => URL . createObjectURL ( file ) ;
11
+
12
+ // FORMAT DATE TIME
13
+ export const formatDateTime = ( dateString : Date | string ) => {
14
+ const dateTimeOptions : Intl . DateTimeFormatOptions = {
15
+ // weekday: "short", // abbreviated weekday name (e.g., 'Mon')
16
+ month : "short" , // abbreviated month name (e.g., 'Oct')
17
+ day : "numeric" , // numeric day of the month (e.g., '25')
18
+ year : "numeric" , // numeric year (e.g., '2023')
19
+ hour : "numeric" , // numeric hour (e.g., '8')
20
+ minute : "numeric" , // numeric minute (e.g., '30')
21
+ hour12 : true , // use 12-hour clock (true) or 24-hour clock (false)
22
+ } ;
23
+
24
+ const dateDayOptions : Intl . DateTimeFormatOptions = {
25
+ weekday : "short" , // abbreviated weekday name (e.g., 'Mon')
26
+ year : "numeric" , // numeric year (e.g., '2023')
27
+ month : "2-digit" , // abbreviated month name (e.g., 'Oct')
28
+ day : "2-digit" , // numeric day of the month (e.g., '25')
29
+ } ;
30
+
31
+ const dateOptions : Intl . DateTimeFormatOptions = {
32
+ month : "short" , // abbreviated month name (e.g., 'Oct')
33
+ year : "numeric" , // numeric year (e.g., '2023')
34
+ day : "numeric" , // numeric day of the month (e.g., '25')
35
+ } ;
36
+
37
+ const timeOptions : Intl . DateTimeFormatOptions = {
38
+ hour : "numeric" , // numeric hour (e.g., '8')
39
+ minute : "numeric" , // numeric minute (e.g., '30')
40
+ hour12 : true , // use 12-hour clock (true) or 24-hour clock (false)
41
+ } ;
42
+
43
+ const formattedDateTime : string = new Date ( dateString ) . toLocaleString (
44
+ "en-US" ,
45
+ dateTimeOptions
46
+ ) ;
47
+
48
+ const formattedDateDay : string = new Date ( dateString ) . toLocaleString (
49
+ "en-US" ,
50
+ dateDayOptions
51
+ ) ;
52
+
53
+ const formattedDate : string = new Date ( dateString ) . toLocaleString (
54
+ "en-US" ,
55
+ dateOptions
56
+ ) ;
57
+
58
+ const formattedTime : string = new Date ( dateString ) . toLocaleString (
59
+ "en-US" ,
60
+ timeOptions
61
+ ) ;
62
+
63
+ return {
64
+ dateTime : formattedDateTime ,
65
+ dateDay : formattedDateDay ,
66
+ dateOnly : formattedDate ,
67
+ timeOnly : formattedTime ,
68
+ } ;
69
+ } ;
70
+
71
+ export function encryptKey ( passkey : string ) {
72
+ return btoa ( passkey ) ;
73
+ }
74
+
75
+ export function decryptKey ( passkey : string ) {
76
+ return atob ( passkey ) ;
77
+ }
0 commit comments