@@ -5,7 +5,8 @@ export default class extends Controller {
55 static classes = [ "urgent" ]
66 static values = {
77 targetTime : String ,
8- durationHours : Number
8+ durationHours : Number ,
9+ showEarlyHours : { type : Number , default : 24 }
910 }
1011
1112 connect ( ) {
@@ -49,11 +50,11 @@ export default class extends Controller {
4950 }
5051
5152 const diff = this . targetDate - now ;
52- const twentyFourHoursInMillis = 24 * 60 * 60 * 1000 ;
53+ const showEarlyInMillis = this . showEarlyHoursValue * 60 * 60 * 1000 ;
5354 const twoHoursInMillis = 2 * 60 * 60 * 1000 ;
54-
55- // Hide if more than 24 hours away or if event is over
56- if ( diff > twentyFourHoursInMillis || now >= this . endDate ) {
55+
56+ // Hide if more than showEarlyHours away or if event is over
57+ if ( diff > showEarlyInMillis || now >= this . endDate ) {
5758 this . hideBanner ( ) ;
5859 if ( now >= this . endDate && this . interval ) {
5960 clearInterval ( this . interval ) ; // Stop interval only if event ended
@@ -75,21 +76,32 @@ export default class extends Controller {
7576 this . updateCountdown ( now ) ;
7677 this . element . classList . add ( this . urgentClass ) ;
7778 } else {
78- // Between 2 and 24 hours left: Show day + time
79+ // Between 2 hours and showEarlyHours left: Show day + time
7980 const targetLocalDate = this . targetDate ; // Already a Date object
8081 const today = new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) ) ;
8182 const tomorrow = new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) + 1 ) ;
8283 const targetDay = new Date ( targetLocalDate . getFullYear ( ) , targetLocalDate . getMonth ( ) , targetLocalDate . getDate ( ) ) ;
8384
84- let dayPrefix = "Live on X" ; // Default/Fallback
85+ let statusText ;
8586 if ( targetDay . getTime ( ) === today . getTime ( ) ) {
86- dayPrefix = "Live on X today" ;
87+ const formattedTime = targetLocalDate . toLocaleString ( undefined , { hour : 'numeric' , minute : '2-digit' } ) ;
88+ statusText = `Live today at ${ formattedTime } ` ;
8789 } else if ( targetDay . getTime ( ) === tomorrow . getTime ( ) ) {
88- dayPrefix = "Live on X tomorrow" ;
89- } // Future dates > tomorrow are handled by the 24h check above
90-
91- const formattedTime = targetLocalDate . toLocaleString ( undefined , { hour : 'numeric' , minute : '2-digit' } ) ;
92- this . statusTarget . textContent = `${ dayPrefix } at ${ formattedTime } ` ;
90+ const formattedTime = targetLocalDate . toLocaleString ( undefined , { hour : 'numeric' , minute : '2-digit' } ) ;
91+ statusText = `Live tomorrow at ${ formattedTime } ` ;
92+ } else {
93+ // Future dates beyond tomorrow
94+ const formattedDate = targetLocalDate . toLocaleString ( undefined , {
95+ weekday : 'short' ,
96+ month : 'short' ,
97+ day : 'numeric' ,
98+ hour : 'numeric' ,
99+ minute : '2-digit'
100+ } ) ;
101+ statusText = `Live on ${ formattedDate } ` ;
102+ }
103+
104+ this . statusTarget . textContent = statusText ;
93105 this . element . classList . remove ( this . urgentClass ) ;
94106 }
95107 }
0 commit comments