File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed
packages/cubejs-backend-shared/src Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -266,9 +266,33 @@ export const extractDate = (data: any): string | null => {
266266 data = JSON . parse ( JSON . stringify ( data ) ) ;
267267 const value = data [ 0 ] && data [ 0 ] [ Object . keys ( data [ 0 ] ) [ 0 ] ] ;
268268 if ( ! value ) {
269- return value ;
269+ return null ;
270+ }
271+
272+ // Most common formats
273+ const formats = [
274+ moment . ISO_8601 ,
275+ 'YYYY-MM-DD HH:mm:ss' ,
276+ 'YYYY-MM-DD HH:mm:ss.SSS' ,
277+ 'YYYY-MM-DDTHH:mm:ss.SSS' ,
278+ 'YYYY-MM-DDTHH:mm:ss'
279+ ] ;
280+
281+ let parsedMoment ;
282+
283+ if ( value . includes ( 'Z' ) || / ( [ + - ] \d { 2 } : ? \d { 2 } ) $ / . test ( value . trim ( ) ) ) {
284+ // We have timezone info
285+ parsedMoment = moment ( value , formats , true ) ;
286+ } else {
287+ // If no tz info - treat as in UTC
288+ parsedMoment = moment . utc ( value , formats , true ) ;
270289 }
271- return moment . tz ( value , 'UTC' ) . format ( moment . HTML5_FMT . DATETIME_LOCAL_MS ) ;
290+
291+ if ( ! parsedMoment . isValid ( ) ) {
292+ return null ;
293+ }
294+
295+ return parsedMoment . utc ( ) . format ( moment . HTML5_FMT . DATETIME_LOCAL_MS ) ;
272296} ;
273297
274298export const addSecondsToLocalTimestamp = ( timestamp : string , timezone : string , seconds : number ) : Date => {
You can’t perform that action at this time.
0 commit comments