@@ -59,6 +59,13 @@ const BookingComponent = () => {
59
59
return correctedCallsign ;
60
60
}
61
61
62
+ function parseDateUTC ( dateString ) {
63
+ if ( ! dateString ) return new Date ( 0 ) ; // Default to epoch for missing dates
64
+ // Replace space with 'T' and ensure 'Z' at the end for UTC
65
+ const formattedDate = dateString . replace ( " " , "T" ) ;
66
+ return new Date ( formattedDate . endsWith ( "Z" ) ? formattedDate : `${ formattedDate } Z` ) ;
67
+ }
68
+
62
69
ControlCenterBookings . data . forEach ( booking => {
63
70
const bookingDate = new Date ( booking . time_start ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
64
71
const dateIndex = dateArray . findIndex ( dateObj => dateObj . date === bookingDate ) ;
@@ -69,12 +76,15 @@ const BookingComponent = () => {
69
76
70
77
VATSIMNetworkData . controllers . forEach ( session => {
71
78
if ( acceptedFIRsRegex . test ( session . callsign ) && ! mentorRegex . test ( session . callsign ) ) {
72
- const correctedCallsign = getBookableCallsign ( session . callsign , session . frequency ) ;
79
+ const normalizeCallsign = ( callsign ) => callsign . replace ( / _ + / g, "_" ) ;
80
+ const correctedCallsign = getBookableCallsign ( normalizeCallsign ( session . callsign ) , session . frequency ) ;
73
81
session . callsign = correctedCallsign ;
74
82
const existingBooking = dateArray [ 0 ] . data . find ( booking => booking . callsign === session . callsign ) ;
75
83
// Merge if existing booking exists and now is after the booking start time.
76
- if ( existingBooking && existingBooking . time_start > new Date ( ) ) {
84
+
85
+ if ( existingBooking && parseDateUTC ( existingBooking . time_start ) . getTime ( ) < new Date ( ) . getTime ( ) ) {
77
86
existingBooking . name = session . name ;
87
+ existingBooking . logon_time = session . logon_time ;
78
88
} else {
79
89
dateArray [ 0 ] . data . push ( {
80
90
...session ,
@@ -86,8 +96,9 @@ const BookingComponent = () => {
86
96
87
97
// Sort the first date (in most cases today) by time, so ad-hoc sessions also are sorted correctly.
88
98
dateArray [ 0 ] . data . sort ( ( a , b ) => {
89
- const aTime = a . time_start || a . logon_time ;
90
- const bTime = b . time_start || b . logon_time ;
99
+ const aTime = parseDateUTC ( a . time_start || a . logon_time ) . getTime ( ) ;
100
+ const bTime = parseDateUTC ( b . time_start || b . logon_time ) . getTime ( ) ;
101
+
91
102
return new Date ( aTime ) - new Date ( bTime ) ;
92
103
} ) ;
93
104
@@ -124,9 +135,9 @@ const BookingComponent = () => {
124
135
</ tr >
125
136
{ date . data . map ( ( booking ) => (
126
137
< tr key = { booking . id } className = "h-6 even:bg-gray-50 odd:bg-white dark:even:bg-tertiary dark:odd:bg-black" >
127
- { booking . name ? < td className = "pl-[4px] text-[#447b68] font-bold" > < img class = "circle" src = "img/icons/circle-solid.svg" alt = "" /> { booking . callsign } </ td > : < td className = "pl-[4px]" > < img class = "circle" src = "img/icons/circle-regular.svg" alt = "" /> { booking . callsign } </ td > }
128
- < td className = "pl-[4px ]" > { bookingType ( booking ) } </ td >
129
- < td className = "pl-[4px]" > { booking . time_start ? convertZulu ( booking . time_start ) : "" } { booking . logon_time ? convertZulu ( fixNetworkTime ( booking . logon_time ) ) : "" } </ td >
138
+ { booking . name ? < td className = "pl-[4px] text-[#447b68] font-bold" > < img className = "circle" src = "img/icons/circle-solid.svg" alt = "" /> { booking . callsign } </ td > : < td className = "pl-[4px]" > < img className = "circle" src = "img/icons/circle-regular.svg" alt = "" /> { booking . callsign } </ td > }
139
+ < td className = "px-[15px ]" > { bookingType ( booking ) } </ td >
140
+ < td className = "pl-[4px]" > { booking . time_start && ! booking . logon_time ? convertZulu ( booking . time_start ) : "" } { booking . logon_time ? convertZulu ( fixNetworkTime ( booking . logon_time ) ) : "" } </ td >
130
141
< td className = "pl-[4px]" > { convertZulu ( booking . time_end ) } </ td >
131
142
</ tr >
132
143
) ) }
0 commit comments