@@ -9,3 +9,82 @@ export function getDarkModeColor(color: string) {
9
9
export function getColorName ( color : string ) {
10
10
return color . replace ( '-700' , '' ) . replace ( 'bg-' , '' ) ;
11
11
}
12
+
13
+ export const formatDate = ( inputString : Date ) => {
14
+ const dateObj = new Date ( inputString ) ;
15
+ const day = dateObj . getDate ( ) ;
16
+ const monthIndex = dateObj . getMonth ( ) ;
17
+ const year = dateObj . getFullYear ( ) ;
18
+ const hours = dateObj . getHours ( ) ;
19
+ const minutes = dateObj . getMinutes ( ) ;
20
+ // Format the day with appropriate suffix (e.g., 1st, 2nd, 3rd, 4th, etc.)
21
+ const dayWithSuffix = getDayWithSuffix ( day ) ;
22
+ // Get the month name from the month index
23
+ const monthNames = [
24
+ 'January' ,
25
+ 'February' ,
26
+ 'March' ,
27
+ 'April' ,
28
+ 'May' ,
29
+ 'June' ,
30
+ 'July' ,
31
+ 'August' ,
32
+ 'September' ,
33
+ 'October' ,
34
+ 'November' ,
35
+ 'December' ,
36
+ ] ;
37
+ const monthName = monthNames [ monthIndex ] ;
38
+ // Format the time in 12-hour clock format with AM/PM
39
+ const amOrPm = hours >= 12 ? 'PM' : 'AM' ;
40
+ const formattedHours = hours % 12 || 12 ;
41
+ const formattedMinutes = minutes . toString ( ) . padStart ( 2 , '0' ) ;
42
+ return `${ dayWithSuffix } ${ monthName } ${ year } , ${ formattedHours } :${ formattedMinutes } ${ amOrPm } ` ;
43
+ } ;
44
+
45
+ export const secondFormatDate = ( inputString : Date ) => {
46
+ const dateObj = new Date ( inputString ) ;
47
+ const day = dateObj . getDate ( ) ;
48
+ const monthIndex = dateObj . getMonth ( ) ;
49
+ const hours = dateObj . getHours ( ) ;
50
+ const minutes = dateObj . getMinutes ( ) ;
51
+ // Format the day with appropriate suffix (e.g., 1st, 2nd, 3rd, 4th, etc.)
52
+ const dayWithSuffix = getDayWithSuffix ( day ) ;
53
+ // Get the month name from the month index
54
+ const monthNames = [
55
+ 'Jan' ,
56
+ 'Feb' ,
57
+ 'Mar' ,
58
+ 'Apr' ,
59
+ 'May' ,
60
+ 'Jun' ,
61
+ 'July' ,
62
+ 'Aug' ,
63
+ 'Sept' ,
64
+ 'Oct' ,
65
+ 'Nov' ,
66
+ 'Dec' ,
67
+ ] ;
68
+ const monthName = monthNames [ monthIndex ] ;
69
+ // Format the time in 12-hour clock format with AM/PM
70
+ const amOrPm = hours >= 12 ? 'PM' : 'AM' ;
71
+ const formattedHours = hours % 12 || 12 ;
72
+ const formattedMinutes = minutes . toString ( ) . padStart ( 2 , '0' ) ;
73
+ return `${ dayWithSuffix } ${ monthName } , ${ formattedHours } :${ formattedMinutes } ${ amOrPm } ` ;
74
+ } ;
75
+
76
+ export const getDayWithSuffix = ( day : number ) => {
77
+ if ( day >= 11 && day <= 13 ) {
78
+ return day + 'th' ;
79
+ }
80
+ switch ( day % 10 ) {
81
+ case 1 :
82
+ return day + 'st' ;
83
+ case 2 :
84
+ return day + 'nd' ;
85
+ case 3 :
86
+ return day + 'rd' ;
87
+ default :
88
+ return day + 'th' ;
89
+ }
90
+ } ;
0 commit comments