Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hardcoded Time Zones #2181

Merged
merged 4 commits into from
Dec 11, 2024
Merged
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
105 changes: 90 additions & 15 deletions src/org/labkey/test/tests/NonStandardDateAndTimeFormatTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.labkey.test.tests;

import org.apache.commons.lang3.SystemUtils;
import org.jetbrains.annotations.Nullable;
import org.junit.AfterClass;
import org.junit.Before;
Expand Down Expand Up @@ -36,8 +37,13 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

@Category({Daily.class})
public class NonStandardDateAndTimeFormatTest extends BaseWebDriverTest
Expand All @@ -62,6 +68,8 @@ public class NonStandardDateAndTimeFormatTest extends BaseWebDriverTest

private final PortalHelper _portalHelper = new PortalHelper(this);

private static final TimeZone TIME_ZONE = TimeZone.getDefault();

@Override
public List<String> getAssociatedModules()
{
Expand Down Expand Up @@ -241,12 +249,19 @@ public void testLists() throws IOException, CommandException
dateTimeCol01, "May 1, 2005 6:32 pm",
dateTimeCol02, "6/1/24 10:00"), false);

Calendar calTime02 = Calendar.getInstance();
calTime02.set(Calendar.HOUR_OF_DAY, 14);
calTime02.set(Calendar.MINUTE, 42);

Calendar calDateTime02 = Calendar.getInstance();
calDateTime02.set(2024, Calendar.JUNE, 1, 10, 0);

Map<String, String> expectedRowValues = Map.of(dateCol01, "April 01, 2021",
dateCol02, "2019-52 AD",
timeCol01, "12:32:00.00 AM",
timeCol02, "2:42 PM PST",
timeCol02, String.format("2:42 PM %s", getTimezoneDesc(calTime02.getTime())),
dateTimeCol01, "May 01, 2005 06:32:00.00 PM",
dateTimeCol02, "10:00 AM PDT 2024-22 AD");
dateTimeCol02, String.format("10:00 AM %s 2024-22 AD", getTimezoneDesc(calDateTime02.getTime())));

EditListDefinitionPage listDefinitionPage = _listHelper.goToEditDesign(listFormat);
DomainFormPanel domainEditor = listDefinitionPage.getFieldsPanel();
Expand All @@ -273,9 +288,26 @@ public void testLists() throws IOException, CommandException
timeCol01, "12:32 am",
dateTimeCol01, "May 1, 2005 6:32 pm"), false);

expectedRowValues = Map.of(dateCol01, "01/04/21",
timeCol01, "0:32:0 AM -0800",
dateTimeCol01, "Sunday May 01 121 2005 18:32:0 -07");
Calendar calTime01 = Calendar.getInstance();
calTime01.set(Calendar.HOUR_OF_DAY, 0);
calTime01.set(Calendar.MINUTE, 32);

Calendar calDateTime01 = Calendar.getInstance();
calDateTime01.set(2005, Calendar.MAY, 1, 18, 32);

expectedRowValues = new HashMap<>();
expectedRowValues.put(dateCol01, "01/04/21");
expectedRowValues.put(timeCol01, String.format("0:32:0 AM %s00", getTimezoneOffset(calTime01.getTime())));

if (SystemUtils.IS_OS_WINDOWS)
{
expectedRowValues.put(dateTimeCol01, "Sunday May 01 121 2005 18:32:0 Z");
}
else
{
expectedRowValues.put(dateTimeCol01,
String.format("Sunday May 01 121 2005 18:32:0 %s", getTimezoneOffset(calDateTime01.getTime())));
}

listDefinitionPage = _listHelper.goToEditDesign(listInherit);
domainEditor = listDefinitionPage.getFieldsPanel();
Expand Down Expand Up @@ -511,10 +543,28 @@ public void testDataClass() throws IOException, CommandException
dateCol, "December 23, 2024",
timeCol, "02:45:00.00 PM", "Flag", "");

Map<String, String> expectedInheritedData = Map.of("Name", "A",
dateTimeCol, "Monday December 23 358 2024 14:45:0 -08",
dateCol, "23/12/24",
timeCol, "2:45:0 PM -0800", "Flag", "");
Calendar calDateTime = Calendar.getInstance();
calDateTime.set(2024, Calendar.DECEMBER, 23, 14, 45);

Calendar calTime = Calendar.getInstance();
calTime.set(Calendar.HOUR_OF_DAY, 14);
calTime.set(Calendar.MINUTE, 45);

Map<String, String> expectedInheritedData = new HashMap<>();
expectedInheritedData.put("Name", "A");
expectedInheritedData.put(dateCol, "23/12/24");
expectedInheritedData.put(timeCol, String.format("2:45:0 PM %s00", getTimezoneOffset(calTime.getTime())));
expectedInheritedData.put("Flag", "");

if (SystemUtils.IS_OS_WINDOWS)
{
expectedInheritedData.put(dateTimeCol, "Monday December 23 358 2024 14:45:0 Z");
}
else
{
expectedInheritedData.put(dateTimeCol,
String.format("Monday December 23 358 2024 14:45:0 %s", getTimezoneOffset(calDateTime.getTime())));
}

populateDataClass(getProjectName(), dcFormat, bulkData);
populateDataClass(getProjectName(), dcInherit, bulkData);
Expand Down Expand Up @@ -736,19 +786,31 @@ public void testScopeFromSiteToSubFolder() throws IOException, CommandException
true, String.format("%s %s", nsSiteDateFormat, nsSiteTimeFormat), "",
false, false);

Calendar calDateTime = Calendar.getInstance();
calDateTime.set(2024, Calendar.DECEMBER, 23, 14, 25);

Calendar calTime = Calendar.getInstance();
calTime.set(Calendar.HOUR_OF_DAY, 14);
calTime.set(Calendar.MINUTE, 45);

log("Sanity check that the DataClass data is formatted in the project and subfolder.");
Map<String, String> expectedFormatData = Map.of("Name", "P1",
dateTimeCol, "December 23, 2024 14:45 PST",
dateTimeCol, String.format("December 23, 2024 14:45 %s", getTimezoneDesc(calDateTime.getTime())),
dateCol, "December 23, 2024",
timeCol, "14:45 PST",
timeCol, String.format("14:45 %s", getTimezoneDesc(calTime.getTime())),
"Flag", "");

validateDataIsFormatted(folderProject, dcInProj, expectedFormatData);

calDateTime.set(2024, Calendar.NOVEMBER, 28, 11, 11);

calTime.set(Calendar.HOUR_OF_DAY, 11);
calTime.set(Calendar.MINUTE, 11);

expectedFormatData = Map.of("Name", "C1",
dateTimeCol, "November 28, 2024 11:11 PST",
dateTimeCol, String.format("November 28, 2024 11:11 %s", getTimezoneDesc(calDateTime.getTime())),
dateCol, "November 28, 2024",
timeCol, "11:11 PST",
timeCol, String.format("11:11 %s", getTimezoneDesc(calTime.getTime())),
"Flag", "");
validateDataIsFormatted(subFolderPath, dcInSub, expectedFormatData);
validateDataIsFormatted(subFolderPath, dcInProj, expectedFormatData);
Expand All @@ -770,9 +832,9 @@ public void testScopeFromSiteToSubFolder() throws IOException, CommandException

log("Check the format in the DataClasses");
expectedFormatData = Map.of("Name", "C1",
dateTimeCol, "Thursday November 28, 2024 11:11 (PST)",
dateTimeCol, String.format("Thursday November 28, 2024 11:11 (%s)", getTimezoneDesc(calDateTime.getTime())),
dateCol, "Thursday November 28, 2024",
timeCol, "11:11 (PST)",
timeCol, String.format("11:11 (%s)", getTimezoneDesc(calTime.getTime())),
"Flag", "");
validateDataIsFormatted(subFolderPath, dcInSub, expectedFormatData);
validateDataIsFormatted(subFolderPath, dcInProj, expectedFormatData);
Expand Down Expand Up @@ -1340,4 +1402,17 @@ private List<String> getProjectValidationWarnings(String scope)
return warnings;
}

// Timezone description (PST vs. PDT) is dependent on the date.
private String getTimezoneDesc(Date date)
{
boolean isDT = TIME_ZONE.inDaylightTime(date);
return TIME_ZONE.getDisplayName(isDT, 0, Locale.getDefault());
}

// Timezone offset from GMT is dependent on the date
private String getTimezoneOffset(Date date)
{
return String.format("%+03d", TIME_ZONE.getOffset(date.getTime()) / 1000 / 60 / 60);
}

}