@@ -4,6 +4,8 @@ Ext4.ns('LDK');
44 * Static helpers designed to help with type conversion in JS.
55 */
66LDK . ConvertUtils = new function ( ) {
7+ var verboseLogging = false ;
8+
79 var DATEFORMATS = LABKEY . Utils . getDateAltFormats ( ) . split ( '|' ) ;
810 DATEFORMATS . push ( 'Y/m/d H:i:s' ) ;
911 DATEFORMATS . push ( 'n-j-Y' ) ;
@@ -16,7 +18,7 @@ LDK.ConvertUtils = new function(){
1618 //@private
1719
1820 //adapted from Ext.field.Date. will parse a date in the given format, returning null if it does not match
19- function safeParseDate ( value , format , useStrict ) {
21+ function safeParseDate ( value , format , useStrict , verboseLogging ) {
2022 var result = null ,
2123 parsedDate ;
2224
@@ -26,28 +28,42 @@ LDK.ConvertUtils = new function(){
2628
2729 useStrict = Ext4 . isDefined ( useStrict ) ? useStrict : false ;
2830
31+ // The core of the parsing problem comes from JS Date.parse() treating ISO 8601 short differently from other date formats:
32+ // https://www.w3.org/TR/NOTE-datetime
33+ // Example:
34+ // new Date('2024-01-01')
35+ // Sun Dec 31 2023 16:00:00 GMT-0800 (Pacific Standard Time)
36+ // new Date('1/1/2024')
37+ // Mon Jan 01 2024 00:00:00 GMT-0800 (Pacific Standard Time)
38+ // Therefore special case this format and append the browser's time zone:
39+ if ( format === 'c' && value && value . length === 10 ) {
40+ if ( verboseLogging ) {
41+ console . log ( 'switching from c to Y-m-d format' )
42+ }
43+
44+ format = 'Y-m-d' ;
45+ }
46+
2947 if ( Ext4 . Date . formatContainsHourInfo ( format ) ) {
3048 // if parse format contains hour information, no DST adjustment is necessary
3149 result = Ext4 . Date . parse ( value , format , useStrict ) ;
3250 } else {
33- // The core of the parsing problem comes from JS Date.parse() treating ISO 8601 short differently from other date formats:
34- // https://www.w3.org/TR/NOTE-datetime
35- // Example:
36- // new Date('2024-01-01')
37- // Sun Dec 31 2023 16:00:00 GMT-0800 (Pacific Standard Time)
38- // new Date('1/1/2024')
39- // Mon Jan 01 2024 00:00:00 GMT-0800 (Pacific Standard Time)
40-
41- // Therefore special case this format and append the browser's time zone:
42- if ( format === 'c' && value . length === 10 ) {
43- format = 'Y-m-d' ;
44- }
45-
4651 parsedDate = Ext4 . Date . parse ( value , format , useStrict ) ;
4752 if ( parsedDate ) {
4853 result = Ext4 . Date . clearTime ( parsedDate ) ;
4954 }
5055 }
56+
57+ // TODO: added for insight into TeamCity test failures. Ultimately remove this.
58+ if ( verboseLogging && result ) {
59+ var msg = 'Parsing, raw value: ' + value + ', format: ' + format + ', result: ' + result ;
60+ console . log ( msg ) ;
61+
62+ LDK . Utils . logToServer ( {
63+ level : 'INFO' ,
64+ message : msg
65+ } )
66+ }
5167 return result ;
5268 }
5369
@@ -86,7 +102,7 @@ LDK.ConvertUtils = new function(){
86102
87103 var val ;
88104 for ( var i = 0 ; i < formats . length ; ++ i ) {
89- val = safeParseDate ( value , formats [ i ] ) ;
105+ val = safeParseDate ( value , formats [ i ] , true , verboseLogging ) ;
90106 if ( val ) {
91107 break ;
92108 }
@@ -113,6 +129,10 @@ LDK.ConvertUtils = new function(){
113129 } , this ) ;
114130 }
115131 } , this ) ;
132+ } ,
133+
134+ setVerboseLogging : function ( val ) {
135+ verboseLogging = val ;
116136 }
117137 }
118138} ;
0 commit comments