Skip to content

Commit

Permalink
Fix error when splitting DateTime format string (#2173)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-danield authored Dec 6, 2024
1 parent 4b634e1 commit 4985b2c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/org/labkey/test/LabKeySiteWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,8 @@ public void clickProject(String project)
public void clickProject(String project, boolean assertDestination)
{
projectMenu().navigateToProject(project);
// After clicking menu item mouse could be left in a position that would be over an element that could have a pop-up.
mouseOut();
if (assertDestination)
{
acceptTermsOfUse(null, true);
Expand Down
25 changes: 16 additions & 9 deletions src/org/labkey/test/components/domain/DomainFormPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,28 @@ else if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.Time))
else if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.DateAndTime))
{

// Identify the part of the format that is the date and the part that is the time. Take into account
// a data format may include spaces (time does not).
String format = fieldDefinition.getFormat().trim();
int index = format.lastIndexOf(" ");
// Identify the part of the format that is the date and the part that is the time.
String formatStr = fieldDefinition.getFormat().trim();
int index = formatStr.indexOf(":");

if (format.substring(index + 1).contains(":"))
if (index == -1)
{
fieldRow.setDateTimeFormat(
DATE_FORMAT.get(format.substring(0, index)),
TIME_FORMAT.get(format.substring(index + 1)));
// If there is no ':' then it is a date only format.
fieldRow.setDateTimeFormat(DATE_FORMAT.get(formatStr));
}
else
{
fieldRow.setDateTimeFormat(DATE_FORMAT.get(format));
// Split the format into the date part and the time part. Take into account that the date part may
// have several spaces and the time part may have a space if there is an am/pm indicator.
// Find the last index of the ' ' before the ':'.
String tmpStr = formatStr.substring(0, index);
index = tmpStr.lastIndexOf(" ");

fieldRow.setDateTimeFormat(
DATE_FORMAT.get(formatStr.substring(0, index)),
TIME_FORMAT.get(formatStr.substring(index + 1)));
}

}
else
{
Expand Down
3 changes: 2 additions & 1 deletion src/org/labkey/test/tests/SimpleModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ private void doTestTableAudit()

// check the row level audit details
popLocation();
waitForElement(Locator.linkWithText("vehicle.Models"));
selectSchema(VEHICLE_SCHEMA);
selectQuery(VEHICLE_SCHEMA, "Models");
assertElementPresent(Locator.linkWithText("view data"));
Expand Down Expand Up @@ -1214,7 +1215,7 @@ private void doTestReportCreatedDate()
{
log("Verify module report \"created\" date");
click(Locator.tag("span").withClass("fa-list-ul").notHidden());
waitForText("2015-08-01");
waitForText("August 01 2015");
}

@LogMethod
Expand Down
4 changes: 1 addition & 3 deletions src/org/labkey/test/tests/list/ListDateAndTimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1113,11 +1113,9 @@ public void testInvalidDateAndTimeInsert() throws IOException, CommandException
* <p>
* Test setting the format property on a date-only, time-only and DateTime field.
* </p>
* @throws IOException Can be thrown by helper that checks if the list already exists.
* @throws CommandException Can be thrown by helper that checks if the list already exists.
*/
@Test
public void testDateAndTimeFormat() throws IOException, CommandException
public void testDateAndTimeFormat()
{
DATE_FORMAT dateFormat01 = DATE_FORMAT.Default;
TIME_FORMAT timeFormat01 = TIME_FORMAT.hh_mm_a;
Expand Down

0 comments on commit 4985b2c

Please sign in to comment.