diff --git a/api/src/org/labkey/api/data/ColumnInfoTests.jsp b/api/src/org/labkey/api/data/ColumnInfoTests.jsp index d7c901cd073..82ef6a79d29 100644 --- a/api/src/org/labkey/api/data/ColumnInfoTests.jsp +++ b/api/src/org/labkey/api/data/ColumnInfoTests.jsp @@ -25,6 +25,7 @@ This tests uses MockRequest to test some expected Headers and Meta tags for vari var result = col.convert(val); assertNotNull(result); //assertEquals(col.getJdbcType().getJavaClass(), result.getClass()); + assertEquals(expected.getClass(), result.getClass()); assertEquals(expected, result); } @@ -159,9 +160,27 @@ This tests uses MockRequest to test some expected Headers and Meta tags for vari case INTEGER -> {} case REAL -> {} case SMALLINT, TINYINT -> {} - case DATE -> {} - case TIME -> {} - case TIMESTAMP -> {} + case DATE -> + { + testConvert(type, java.sql.Date.valueOf("2024-01-15"), "2024-01-15"); + testConvert(type, java.sql.Date.valueOf("2024-01-15"), java.sql.Date.valueOf("2024-01-15")); + testConvertsToNull(type, null); + testConvertsToNull(type, ""); + } + case TIME -> + { + testConvert(type, java.sql.Time.valueOf("14:30:00"), "14:30:00"); + testConvert(type, java.sql.Time.valueOf("14:30:00"), java.sql.Time.valueOf("14:30:00")); + testConvertsToNull(type, null); + testConvertsToNull(type, ""); + } + case TIMESTAMP -> + { + testConvert(type, java.sql.Timestamp.valueOf("2024-01-15 14:30:00"), "2024-01-15 14:30:00"); + testConvert(type, java.sql.Timestamp.valueOf("2024-01-15 14:30:00"), java.sql.Timestamp.valueOf("2024-01-15 14:30:00")); + testConvertsToNull(type, null); + testConvertsToNull(type, ""); + } case GUID -> {} case ARRAY, NULL, OTHER -> { /* ignore */ } default -> fail("We missed a JdbcType: " + type.name()); @@ -203,9 +222,27 @@ This tests uses MockRequest to test some expected Headers and Meta tags for vari case BINARY -> {} case FILE_LINK -> {} case ATTACHMENT -> {} - case DATE_TIME -> {} - case DATE -> {} - case TIME -> {} + case DATE_TIME -> + { + testConvert(type, java.sql.Timestamp.valueOf("2024-01-15 14:30:00"), "2024-01-15 14:30:00"); + testConvert(type, java.sql.Timestamp.valueOf("2024-01-15 14:30:00"), java.sql.Timestamp.valueOf("2024-01-15 14:30:00")); + testConvertsToNull(type, null); + testConvertsToNull(type, ""); + } + case DATE -> + { + testConvert(type, java.sql.Date.valueOf("2024-01-15"), "2024-01-15"); + testConvert(type, java.sql.Date.valueOf("2024-01-15"), java.sql.Date.valueOf("2024-01-15")); + testConvertsToNull(type, null); + testConvertsToNull(type, ""); + } + case TIME -> + { + testConvert(type, java.sql.Time.valueOf("14:30:00"), "14:30:00"); + testConvert(type, java.sql.Time.valueOf("14:30:00"), java.sql.Time.valueOf("14:30:00")); + testConvertsToNull(type, null); + testConvertsToNull(type, ""); + } case DOUBLE -> {} case FLOAT -> {} case DECIMAL -> {} diff --git a/api/src/org/labkey/api/exp/PropertyType.java b/api/src/org/labkey/api/exp/PropertyType.java index 6cf8a5dd32c..8d42cc373a2 100644 --- a/api/src/org/labkey/api/exp/PropertyType.java +++ b/api/src/org/labkey/api/exp/PropertyType.java @@ -593,8 +593,6 @@ protected Object convertExcelValue(Cell cell) throws ConversionException { throw new ConversionException(e); } -// int offset = TimeZone.getDefault().getOffset(date.getTime()); -// date.setTime(date.getTime() - offset); } return date; } @@ -611,7 +609,7 @@ public Object convert(Object value) throws ConversionException String strVal = value.toString(); if (DateUtil.isSignedDuration(strVal)) strVal = JdbcType.TIMESTAMP.convert(value).toString(); - return ConvertUtils.convert(strVal, Date.class); + return ConvertUtils.convert(strVal, java.sql.Timestamp.class); } } diff --git a/api/src/org/labkey/api/util/DateUtil.java b/api/src/org/labkey/api/util/DateUtil.java index c919028cde2..1669e2bccca 100644 --- a/api/src/org/labkey/api/util/DateUtil.java +++ b/api/src/org/labkey/api/util/DateUtil.java @@ -1427,7 +1427,7 @@ public static Date combineDateTime(@Nullable Date date, @Nullable Date time) return date; if (null == date) return time; - Date newDate = (Date)date.clone(); + Date newDate = new Date(date.getTime()); newDate.setHours(time.getHours()); newDate.setMinutes(time.getMinutes()); newDate.setSeconds(time.getSeconds()); @@ -1444,7 +1444,7 @@ public static Date getDateOnly(@Nullable Date fullDate) int month = fullDate.getMonth(); int date = fullDate.getDate(); - return new Date(year, month, date); + return new java.sql.Date(year, month, date); } public static TimeZone getTimeZone() diff --git a/api/src/org/labkey/api/util/SubstitutionFormat.java b/api/src/org/labkey/api/util/SubstitutionFormat.java index 1dc46cf36f9..83eea5691b6 100644 --- a/api/src/org/labkey/api/util/SubstitutionFormat.java +++ b/api/src/org/labkey/api/util/SubstitutionFormat.java @@ -82,6 +82,8 @@ public Object format(Object value) return defaultTimeFormat.format(value); else if (value instanceof java.sql.Date) return date.format(value); + else if (value instanceof java.sql.Timestamp) + return defaultDateTimeFormat.format(value).replace('T', ' '); // replace T with whitespace for human readability else if (value instanceof Date dateVal) { // both date and datetime column type are of type Date, format based on time portion of the date value