@@ -242,15 +242,22 @@ export const assembleVegaChart = (
242242 encodingObj [ "type" ] = "nominal" ;
243243 } else if ( fieldMetadata . semanticType == 'YearMonth' ) {
244244 let sampleValues = workingTable . map ( r => r [ field . name ] ) . slice ( 0 , 10 ) ;
245- // Check if values are in yyyy-mm format (temporal) or yyyy-Aug/yyyy-Q1 format (nominal)
246- let isNumericMonth = sampleValues . some ( val => {
245+ // Check if values can be parsed as valid temporal dates (Vega-Lite compatible)
246+ // Temporal: yyyy-mm, yyyy-mm-dd, ISO date formats
247+ // Nominal: 2021-Aug, Q1-2024, etc.
248+ let isValidTemporal = sampleValues . some ( val => {
247249 if ( val && typeof val === 'string' ) {
248- // Match yyyy-mm format (e.g., 2023-01, 2023-12)
249- return / ^ \d { 4 } - \d { 2 } $ / . test ( val . trim ( ) ) ;
250+ const trimmed = val . trim ( ) ;
251+ // Try to parse as date
252+ const date = new Date ( trimmed ) ;
253+ // Check if it's a valid date and follows ISO-like format
254+ // (no letters except 'T' for datetime separator, 'Z' for timezone)
255+ const isISOLike = / ^ [ \d \- : . T Z + ] + $ / . test ( trimmed ) ;
256+ return ! isNaN ( date . getTime ( ) ) && isISOLike ;
250257 }
251258 return false ;
252259 } ) ;
253- encodingObj [ "type" ] = isNumericMonth ? "temporal" : "nominal" ;
260+ encodingObj [ "type" ] = isValidTemporal ? "temporal" : "nominal" ;
254261 } else {
255262 encodingObj [ "type" ] = "temporal" ;
256263 }
0 commit comments