Skip to content

Commit e31c108

Browse files
authored
Merge pull request #246 from LabKey/fb_merge_25.3_to_develop
Merge discvr-25.3 to develop
2 parents 3a14409 + f0b58c1 commit e31c108

File tree

4 files changed

+51
-20
lines changed

4 files changed

+51
-20
lines changed

LDK/resources/web/LDK/ConvertUtils.js

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Ext4.ns('LDK');
44
* Static helpers designed to help with type conversion in JS.
55
*/
66
LDK.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
};

LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616
package org.labkey.test.tests.external.labModules;
1717

1818
import org.apache.commons.lang3.StringUtils;
19-
import org.apache.commons.lang3.time.DateFormatUtils;
20-
import org.apache.commons.lang3.time.DateUtils;
2119
import org.apache.commons.lang3.tuple.Pair;
2220
import org.apache.poi.ss.usermodel.Sheet;
2321
import org.apache.poi.ss.usermodel.Workbook;
2422
import org.junit.Assert;
2523
import org.junit.Test;
2624
import org.junit.experimental.categories.Category;
27-
import org.labkey.api.util.DateUtil;
2825
import org.labkey.remoteapi.CommandException;
2926
import org.labkey.remoteapi.Connection;
3027
import org.labkey.remoteapi.collections.CaseInsensitiveHashMap;
@@ -1499,6 +1496,14 @@ private void samplesTableTest() throws Exception
14991496
new Window.WindowFinder(getDriver()).withTitle("Mark Removed").waitFor();
15001497
Ext4FieldRef.getForLabel(this, "Date Removed").setValue("2017-01-02");
15011498
Ext4FieldRef.getForLabel(this, "Comment").setValue("I removed these samples");
1499+
1500+
// TODO: for debugging date. ultimately remove
1501+
BaseWebDriverTest.getCurrentTest().getArtifactCollector().dumpPageSnapshot("LabModulesTestDate1");
1502+
1503+
// Debug date parsing
1504+
String clientFormattedString = (String)executeScript("return Ext4.Date.format(LDK.ConvertUtils.parseDate('2017-01-02'), 'Y-m-d');");
1505+
assertEquals("Incorrect date parsing", clientFormattedString, "2017-01-02");
1506+
15021507
waitAndClickAndWait(Ext4Helper.Locators.ext4Button("Submit"));
15031508

15041509
dr = new DataRegionTable.DataRegionFinder(getDriver()).withName("query").find();
@@ -1515,7 +1520,7 @@ private void samplesTableTest() throws Exception
15151520
{
15161521
Assert.assertEquals("I removed these samples", row.get("remove_comment"));
15171522
Assert.assertEquals(getUserId(), row.get("removedby"));
1518-
Assert.assertEquals("2017-01-02", dateFormat.format(row.get("dateremoved")));
1523+
Assert.assertEquals("Incorrect date, raw value: " + row.get("dateremoved"), "2017-01-02", dateFormat.format(row.get("dateremoved")));
15191524
}
15201525
}
15211526

LDK/test/src/org/labkey/test/util/external/labModules/LabModuleHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void addRecordsToAssayTemplate(String[][] data, List<String> expectedColu
193193
for (String[] row : data)
194194
{
195195
sb.append(StringUtils.join(row, '\t'));
196-
sb.append(System.getProperty("line.separator"));
196+
sb.append(System.lineSeparator());
197197
}
198198

199199
_test.waitForText("Sample Information");

laboratory/resources/web/laboratory/window/AssaySpreadsheetImportWindow.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Ext4.define('Laboratory.ext.AssaySpreadsheetImportWindow', {
6262
return;
6363
}
6464

65+
// TODO: debugging, ultimately remove this
66+
LDK.ConvertUtils.setVerboseLogging(true);
67+
6568
var models = LDK.StoreUtils.getModelsFromText({
6669
store: win.targetGrid.store,
6770
text: text
@@ -77,6 +80,9 @@ Ext4.define('Laboratory.ext.AssaySpreadsheetImportWindow', {
7780

7881
win.targetGrid.store.add(toAdd);
7982

83+
// TODO: debugging, ultimately remove this
84+
LDK.ConvertUtils.setVerboseLogging(false);
85+
8086
win.close();
8187
}
8288
},{

0 commit comments

Comments
 (0)