@@ -59,11 +59,14 @@ export const ColorbarPlot = observer(function ColorbarPlot() {
5959 } ) ;
6060
6161 // Add the next month to the yLabels
62- const lastDateMonth = new Date ( yLabels [ yLabels . length - 1 ] ) . getMonth ( ) + 1 ;
63- const lastDateYear = new Date ( yLabels [ yLabels . length - 1 ] ) . getFullYear ( ) ;
64- // Note: Javascript correctly handles a month of 13 as the next year
65- const lastDate = new Date ( lastDateYear , lastDateMonth ) ;
66- yLabels . push ( lastDate . toISOString ( ) . split ( "T" ) [ 0 ] ) ;
62+ // We use UTC methods to avoid timezone issues
63+ const lastDate = new Date ( yLabels [ yLabels . length - 1 ] ) ;
64+ // These are 0 based months
65+ const lastDateMonth = new Date ( lastDate ) . getUTCMonth ( ) ;
66+ const lastDateYear = new Date ( lastDate ) . getUTCFullYear ( ) ;
67+ // Javascript correctly handles a month of 12 as the next year
68+ const endDate = new Date ( Date . UTC ( lastDateYear , lastDateMonth + 1 ) ) ;
69+ yLabels . push ( endDate . toISOString ( ) . split ( "T" ) [ 0 ] ) ;
6770
6871 const selectedYMDDate = loadedImages [ currentImageIndex ] . date ;
6972
@@ -90,6 +93,21 @@ export const ColorbarPlot = observer(function ColorbarPlot() {
9093 } ) ;
9194 const datasets : IDataset [ ] = Array . from ( datasetMap . values ( ) ) ;
9295
96+ // After creating the datasets, add a check for date ranges are only 1 month
97+ const invalidDateRanges = datasets . flatMap ( dataset =>
98+ dataset . data . filter ( dataPoint => {
99+ const [ startDate , _endDate ] = dataPoint . y ;
100+ const start = new Date ( startDate ) ;
101+ const end = new Date ( _endDate ) ;
102+ const diffInMonths = ( end . getFullYear ( ) - start . getFullYear ( ) ) * 12 + ( end . getMonth ( ) - start . getMonth ( ) ) ;
103+ return diffInMonths !== 1 ;
104+ } )
105+ ) ;
106+
107+ if ( invalidDateRanges . length > 0 ) {
108+ console . warn ( "Found data points with date ranges greater than 1 month:" , invalidDateRanges ) ;
109+ }
110+
93111 // Note: any is used here as the Bar type doesn't support the `events:` list but the code does
94112 const options : any = {
95113 animation : {
0 commit comments