@@ -20,6 +20,24 @@ import {
2020} from '@/ui' ;
2121import { renderChildren } from '../../lib/utils' ;
2222
23+ // Constants
24+ const MILLISECONDS_PER_WEEK = 7 * 24 * 60 * 60 * 1000 ;
25+
26+ // Helper function to calculate date range from items
27+ function calculateDateRange ( items : any [ ] ) : { minDate : string ; maxDate : string } {
28+ const allDates = items . flatMap ( ( row : any ) =>
29+ ( row . items || [ ] ) . flatMap ( ( item : any ) => [ item . startDate , item . endDate ] )
30+ ) ;
31+
32+ const minTimestamp = Math . min ( ...allDates . map ( ( d : string ) => new Date ( d ) . getTime ( ) ) ) ;
33+ const maxTimestamp = Math . max ( ...allDates . map ( ( d : string ) => new Date ( d ) . getTime ( ) ) ) ;
34+
35+ return {
36+ minDate : new Date ( minTimestamp ) . toISOString ( ) . split ( 'T' ) [ 0 ] ,
37+ maxDate : new Date ( maxTimestamp ) . toISOString ( ) . split ( 'T' ) [ 0 ] ,
38+ } ;
39+ }
40+
2341// Helper function to calculate bar position and width based on dates
2442function calculateBarDimensions (
2543 startDate : string ,
@@ -132,19 +150,9 @@ ComponentRegistry.register(
132150 // Gantt/Airtable-style Timeline
133151 if ( variant === 'gantt' ) {
134152 // Calculate date range from all items
135- const allDates = items . flatMap ( ( row : any ) =>
136- ( row . items || [ ] ) . flatMap ( ( item : any ) => [ item . startDate , item . endDate ] )
137- ) ;
138- const minDate =
139- schema . minDate ||
140- new Date ( Math . min ( ...allDates . map ( ( d : string ) => new Date ( d ) . getTime ( ) ) ) )
141- . toISOString ( )
142- . split ( 'T' ) [ 0 ] ;
143- const maxDate =
144- schema . maxDate ||
145- new Date ( Math . max ( ...allDates . map ( ( d : string ) => new Date ( d ) . getTime ( ) ) ) )
146- . toISOString ( )
147- . split ( 'T' ) [ 0 ] ;
153+ const dateRange = calculateDateRange ( items ) ;
154+ const minDate = schema . minDate || dateRange . minDate ;
155+ const maxDate = schema . maxDate || dateRange . maxDate ;
148156
149157 // Generate time scale headers (months, weeks, etc.)
150158 const timeScale = schema . timeScale || 'month' ;
@@ -169,7 +177,7 @@ ComponentRegistry.register(
169177 while ( current <= end ) {
170178 headers . push (
171179 `Week ${ Math . ceil (
172- ( current . getTime ( ) - start . getTime ( ) ) / ( 7 * 24 * 60 * 60 * 1000 )
180+ ( current . getTime ( ) - start . getTime ( ) ) / MILLISECONDS_PER_WEEK
173181 ) + 1 } `
174182 ) ;
175183 current . setDate ( current . getDate ( ) + 7 ) ;
0 commit comments