From 100129db5719e043e50b5898fb4f8e70f3f5f969 Mon Sep 17 00:00:00 2001 From: bbimber Date: Mon, 7 Apr 2025 15:25:13 -0700 Subject: [PATCH 1/5] Debug/test date parsing --- .../tests/external/labModules/LabModulesTest.java | 11 ++++++++--- .../util/external/labModules/LabModuleHelper.java | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java b/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java index e31b1780..d55570d3 100644 --- a/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java +++ b/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java @@ -16,15 +16,12 @@ package org.labkey.test.tests.external.labModules; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateFormatUtils; -import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.labkey.api.util.DateUtil; import org.labkey.remoteapi.CommandException; import org.labkey.remoteapi.Connection; import org.labkey.remoteapi.collections.CaseInsensitiveHashMap; @@ -1499,6 +1496,14 @@ private void samplesTableTest() throws Exception new Window.WindowFinder(getDriver()).withTitle("Mark Removed").waitFor(); Ext4FieldRef.getForLabel(this, "Date Removed").setValue("2017-01-02"); Ext4FieldRef.getForLabel(this, "Comment").setValue("I removed these samples"); + + // TODO: for debugging date. ultimately remove + checker().withScreenshot("LabModulesTestDate1"); + + // Debug date parsing + String clientFormattedString = (String)executeScript("return Ext4.Date.format(LDK.ConvertUtils.parseDate('2017-01-02'), 'Y-m-d');"); + assertEquals("Incorrect date parsing", clientFormattedString, "2017-01-02"); + waitAndClickAndWait(Ext4Helper.Locators.ext4Button("Submit")); dr = new DataRegionTable.DataRegionFinder(getDriver()).withName("query").find(); diff --git a/LDK/test/src/org/labkey/test/util/external/labModules/LabModuleHelper.java b/LDK/test/src/org/labkey/test/util/external/labModules/LabModuleHelper.java index 828f9769..92f7ef32 100644 --- a/LDK/test/src/org/labkey/test/util/external/labModules/LabModuleHelper.java +++ b/LDK/test/src/org/labkey/test/util/external/labModules/LabModuleHelper.java @@ -193,7 +193,7 @@ public void addRecordsToAssayTemplate(String[][] data, List expectedColu for (String[] row : data) { sb.append(StringUtils.join(row, '\t')); - sb.append(System.getProperty("line.separator")); + sb.append(System.lineSeparator()); } _test.waitForText("Sample Information"); From 0602635768b224ebd9fc427a1abb4a30bbed1c63 Mon Sep 17 00:00:00 2001 From: bbimber Date: Tue, 8 Apr 2025 06:44:29 -0700 Subject: [PATCH 2/5] Debug/test date parsing --- LDK/resources/web/LDK/ConvertUtils.js | 16 ++++++++++++++++ .../external/labModules/LabModulesTest.java | 4 ++-- .../window/AssaySpreadsheetImportWindow.js | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/LDK/resources/web/LDK/ConvertUtils.js b/LDK/resources/web/LDK/ConvertUtils.js index 5773f14b..9725c504 100644 --- a/LDK/resources/web/LDK/ConvertUtils.js +++ b/LDK/resources/web/LDK/ConvertUtils.js @@ -4,6 +4,8 @@ Ext4.ns('LDK'); * Static helpers designed to help with type conversion in JS. */ LDK.ConvertUtils = new function(){ + var verboseLogging = false; + var DATEFORMATS = LABKEY.Utils.getDateAltFormats().split('|'); DATEFORMATS.push('Y/m/d H:i:s'); DATEFORMATS.push('n-j-Y'); @@ -40,6 +42,10 @@ LDK.ConvertUtils = new function(){ // Therefore special case this format and append the browser's time zone: if (format === 'c' && value.length === 10) { + if (this.verboseLogging) { + console.log('switching from c for Y-m-d format') + } + format = 'Y-m-d'; } @@ -48,6 +54,12 @@ LDK.ConvertUtils = new function(){ result = Ext4.Date.clearTime(parsedDate); } } + + if (this.verboseLogging) { + console.log('Parsing, raw value: ' + value); + console.log('format: ' + format); + console.log(result); + } return result; } @@ -113,6 +125,10 @@ LDK.ConvertUtils = new function(){ }, this); } }, this); + }, + + setVerboseLogging: function(val) { + this.verboseLogging = val; } } }; \ No newline at end of file diff --git a/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java b/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java index d55570d3..8a64d61b 100644 --- a/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java +++ b/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java @@ -1498,7 +1498,7 @@ private void samplesTableTest() throws Exception Ext4FieldRef.getForLabel(this, "Comment").setValue("I removed these samples"); // TODO: for debugging date. ultimately remove - checker().withScreenshot("LabModulesTestDate1"); + BaseWebDriverTest.getCurrentTest().getArtifactCollector().dumpPageSnapshot("LabModulesTestDate1"); // Debug date parsing String clientFormattedString = (String)executeScript("return Ext4.Date.format(LDK.ConvertUtils.parseDate('2017-01-02'), 'Y-m-d');"); @@ -1520,7 +1520,7 @@ private void samplesTableTest() throws Exception { Assert.assertEquals("I removed these samples", row.get("remove_comment")); Assert.assertEquals(getUserId(), row.get("removedby")); - Assert.assertEquals("2017-01-02", dateFormat.format(row.get("dateremoved"))); + Assert.assertEquals("Incorrect date, raw value: " + row.get("dateremoved"), "2017-01-02", dateFormat.format(row.get("dateremoved"))); } } diff --git a/laboratory/resources/web/laboratory/window/AssaySpreadsheetImportWindow.js b/laboratory/resources/web/laboratory/window/AssaySpreadsheetImportWindow.js index 62de950b..a8765ef2 100644 --- a/laboratory/resources/web/laboratory/window/AssaySpreadsheetImportWindow.js +++ b/laboratory/resources/web/laboratory/window/AssaySpreadsheetImportWindow.js @@ -62,6 +62,9 @@ Ext4.define('Laboratory.ext.AssaySpreadsheetImportWindow', { return; } + // TODO: debugging, ultimately remove this + LDK.ConvertUtils.setVerboseLogging(true); + var models = LDK.StoreUtils.getModelsFromText({ store: win.targetGrid.store, text: text @@ -77,6 +80,9 @@ Ext4.define('Laboratory.ext.AssaySpreadsheetImportWindow', { win.targetGrid.store.add(toAdd); + // TODO: debugging, ultimately remove this + LDK.ConvertUtils.setVerboseLogging(false); + win.close(); } },{ From a3ec43fce1ecb8a3f4da86d8e98a4fe0bda6d6f4 Mon Sep 17 00:00:00 2001 From: bbimber Date: Tue, 8 Apr 2025 08:56:30 -0700 Subject: [PATCH 3/5] Debug/test date parsing --- LDK/resources/web/LDK/ConvertUtils.js | 43 ++++++++++++++------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/LDK/resources/web/LDK/ConvertUtils.js b/LDK/resources/web/LDK/ConvertUtils.js index 9725c504..93c16d05 100644 --- a/LDK/resources/web/LDK/ConvertUtils.js +++ b/LDK/resources/web/LDK/ConvertUtils.js @@ -28,27 +28,26 @@ LDK.ConvertUtils = new function(){ useStrict = Ext4.isDefined(useStrict) ? useStrict : false; + // The core of the parsing problem comes from JS Date.parse() treating ISO 8601 short differently from other date formats: + // https://www.w3.org/TR/NOTE-datetime + // Example: + // new Date('2024-01-01') + // Sun Dec 31 2023 16:00:00 GMT-0800 (Pacific Standard Time) + // new Date('1/1/2024') + // Mon Jan 01 2024 00:00:00 GMT-0800 (Pacific Standard Time) + // Therefore special case this format and append the browser's time zone: + if (format === 'c' && value && value.length === 10) { + if (this.verboseLogging) { + console.log('switching from c to Y-m-d format') + } + + format = 'Y-m-d'; + } + if (Ext4.Date.formatContainsHourInfo(format)) { // if parse format contains hour information, no DST adjustment is necessary result = Ext4.Date.parse(value, format, useStrict); } else { - // The core of the parsing problem comes from JS Date.parse() treating ISO 8601 short differently from other date formats: - // https://www.w3.org/TR/NOTE-datetime - // Example: - // new Date('2024-01-01') - // Sun Dec 31 2023 16:00:00 GMT-0800 (Pacific Standard Time) - // new Date('1/1/2024') - // Mon Jan 01 2024 00:00:00 GMT-0800 (Pacific Standard Time) - - // Therefore special case this format and append the browser's time zone: - if (format === 'c' && value.length === 10) { - if (this.verboseLogging) { - console.log('switching from c for Y-m-d format') - } - - format = 'Y-m-d'; - } - parsedDate = Ext4.Date.parse(value, format, useStrict); if (parsedDate) { result = Ext4.Date.clearTime(parsedDate); @@ -56,9 +55,13 @@ LDK.ConvertUtils = new function(){ } if (this.verboseLogging) { - console.log('Parsing, raw value: ' + value); - console.log('format: ' + format); - console.log(result); + var msg = 'Parsing, raw value: ' + value + ', format: ' + format + ', result: ' + result; + console.log(msg); + + LDK.Utils.logToServer({ + level: 'INFO', + message: msg + }) } return result; } From 7334c96e0bb80f79009afbc0644e3b5147f550c6 Mon Sep 17 00:00:00 2001 From: bbimber Date: Fri, 11 Apr 2025 10:54:28 -0700 Subject: [PATCH 4/5] Improve debugging for date parse failures --- LDK/resources/web/LDK/ConvertUtils.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/LDK/resources/web/LDK/ConvertUtils.js b/LDK/resources/web/LDK/ConvertUtils.js index 93c16d05..51a89d06 100644 --- a/LDK/resources/web/LDK/ConvertUtils.js +++ b/LDK/resources/web/LDK/ConvertUtils.js @@ -18,7 +18,7 @@ LDK.ConvertUtils = new function(){ //@private //adapted from Ext.field.Date. will parse a date in the given format, returning null if it does not match - function safeParseDate(value, format, useStrict){ + function safeParseDate(value, format, useStrict, verboseLogging){ var result = null, parsedDate; @@ -54,7 +54,8 @@ LDK.ConvertUtils = new function(){ } } - if (this.verboseLogging) { + // TODO: added for insight into TeamCity test failures. Ultimately remove this. + if (verboseLogging && result) { var msg = 'Parsing, raw value: ' + value + ', format: ' + format + ', result: ' + result; console.log(msg); @@ -101,7 +102,7 @@ LDK.ConvertUtils = new function(){ var val; for (var i=0; i < formats.length; ++i) { - val = safeParseDate(value, formats[i]); + val = safeParseDate(value, formats[i], true, verboseLogging); if (val) { break; } From 21f92b9b3931f2f2ee251643ac2a45d8a2beb94d Mon Sep 17 00:00:00 2001 From: bbimber Date: Fri, 11 Apr 2025 12:08:15 -0700 Subject: [PATCH 5/5] Improve debugging for date parse failures --- LDK/resources/web/LDK/ConvertUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LDK/resources/web/LDK/ConvertUtils.js b/LDK/resources/web/LDK/ConvertUtils.js index 51a89d06..a026ffa0 100644 --- a/LDK/resources/web/LDK/ConvertUtils.js +++ b/LDK/resources/web/LDK/ConvertUtils.js @@ -37,7 +37,7 @@ LDK.ConvertUtils = new function(){ // Mon Jan 01 2024 00:00:00 GMT-0800 (Pacific Standard Time) // Therefore special case this format and append the browser's time zone: if (format === 'c' && value && value.length === 10) { - if (this.verboseLogging) { + if (verboseLogging) { console.log('switching from c to Y-m-d format') } @@ -132,7 +132,7 @@ LDK.ConvertUtils = new function(){ }, setVerboseLogging: function(val) { - this.verboseLogging = val; + verboseLogging = val; } } }; \ No newline at end of file