diff --git a/LDK/resources/web/LDK/ConvertUtils.js b/LDK/resources/web/LDK/ConvertUtils.js index 5773f14b..a026ffa0 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'); @@ -16,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; @@ -26,28 +28,42 @@ 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 (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) { - format = 'Y-m-d'; - } - parsedDate = Ext4.Date.parse(value, format, useStrict); if (parsedDate) { result = Ext4.Date.clearTime(parsedDate); } } + + // 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); + + LDK.Utils.logToServer({ + level: 'INFO', + message: msg + }) + } return result; } @@ -86,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; } @@ -113,6 +129,10 @@ LDK.ConvertUtils = new function(){ }, this); } }, this); + }, + + setVerboseLogging: function(val) { + 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 e31b1780..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 @@ -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 + 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');"); + assertEquals("Incorrect date parsing", clientFormattedString, "2017-01-02"); + waitAndClickAndWait(Ext4Helper.Locators.ext4Button("Submit")); dr = new DataRegionTable.DataRegionFinder(getDriver()).withName("query").find(); @@ -1515,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/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"); 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(); } },{