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

DO-20250205-1 #1897

Merged
merged 2 commits into from
Feb 6, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public String toHumanDisplay() {

/**
* Returns a human readable version of this date/time using the system local
* format, converted to the local timezone if neccesary.
* format, converted to the local timezone if necessary.
*
* @see #toHumanDisplay() for a method which does not convert the time to the
* local timezone before rendering it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;

public class DateTimeUtil {
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);


public static String toHumanDisplay(TimeZone theTimeZone, TemporalPrecisionEnum thePrecision, Date theValue, String theValueAsString) {
Calendar value = theTimeZone != null ? Calendar.getInstance(theTimeZone) : Calendar.getInstance();
Expand All @@ -26,7 +23,7 @@ public static String toHumanDisplay(TimeZone theTimeZone, TemporalPrecisionEnum
case MILLI:
case SECOND:
default:
return ourHumanDateTimeFormat.format(value);
return FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM).format(value);
}

}
Expand All @@ -40,7 +37,7 @@ public static String toHumanDisplayLocalTimezone(TemporalPrecisionEnum thePrecis
case MILLI:
case SECOND:
default:
return ourHumanDateTimeFormat.format(theValue);
return FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM).format(theValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.TimeZone;
import java.util.stream.Stream;

import org.apache.commons.lang3.time.FastDateFormat;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
Expand All @@ -18,6 +19,8 @@

public class DateTimeUtilTests {

private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateTimeUtilTests.class.getName());

private static Stream<Arguments> getToHumanDisplayParams() {
return Stream.of(
Arguments.of(TimeZone.getTimeZone("EST"), TemporalPrecisionEnum.YEAR, new Date("2002/02/04"), "dummyValueAsString"),
Expand Down Expand Up @@ -57,16 +60,25 @@ private static Stream<Arguments> getToHumanDisplayLocalTimezoneParams() {
);
}

private static final Locale defaultLocale = Locale.getDefault();;
private static Locale defaultLocale;

@BeforeAll
public static void beforeAll() {
Locale.setDefault(Locale.UK);
defaultLocale = Locale.getDefault();
ourLog.info("Test setup: getting current default locale");
ourLog.info("Locale.getDefault(): " + defaultLocale);
ourLog.info("Test setup: setting default locale to UK for tests");
Locale.setDefault(Locale.UK);
ourLog.info("Locale.getDefault(): " + Locale.getDefault());
ourLog.info("DateTime format: " + FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM));
}

@AfterAll
public static void afterAll() {
ourLog.info("Test teardown: setting default locale back to default");
Locale.setDefault(defaultLocale);
ourLog.info("Locale.getDefault(): " + Locale.getDefault());
ourLog.info("DateTime format: " + FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ protected void readParamsAndExecuteTask(CliContext cliContext, String[] args) th
TimeTracker tt = new TimeTracker();
TimeTracker.Session tts = tt.start("Loading");

if (cliContext.getLocale() != null) {
Locale.setDefault(cliContext.getLocale());
}

setJavaSystemProxyParamsFromParams(args);

Display.displayVersion(System.out);
Expand Down