Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions api/src/org/labkey/api/data/ColumnInfoTests.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 -> {}
Expand Down
4 changes: 1 addition & 3 deletions api/src/org/labkey/api/exp/PropertyType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions api/src/org/labkey/api/util/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions api/src/org/labkey/api/util/SubstitutionFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down