This is an automated email from the ASF dual-hosted git repository. danhaywood pushed a commit to branch CAUSEWAY-3803 in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 4b453ed09a6506dd5e2d3b49095286581b627d26 Author: Dan Haywood <[email protected]> AuthorDate: Tue Jul 9 15:34:41 2024 +0100 CAUSEWAY-3803: adds two new config props for display of temporal value types --- .../value/semantics/TemporalValueSemantics.java | 25 ++++++++++++++++++++++ .../value/semantics/ValueSemanticsAbstract.java | 16 ++++++++++---- .../core/config/CausewayConfiguration.java | 5 +++++ .../temporal/TemporalValueSemanticsProvider.java | 6 +++++- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalValueSemantics.java b/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalValueSemantics.java index 79c999c32d..9d8d822526 100644 --- a/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalValueSemantics.java +++ b/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalValueSemantics.java @@ -24,6 +24,8 @@ import java.time.temporal.Temporal; import org.apache.causeway.applib.annotation.TimePrecision; import org.apache.causeway.commons.internal.exceptions._Exceptions; +import org.springframework.lang.Nullable; + import lombok.Data; import lombok.NonNull; @@ -58,6 +60,29 @@ extends } + @Data + public static class TemporalDisplayPattern { + + /** + * The locale-independent (canonical) pattern used for displaying dates in the UI. + * + * <p> + * By default, a locale-specific date pattern is used (using {@link java.time.format.FormatStyle#MEDIUM} format). + * </p> + */ + private String datePattern; + + /** + * The locale-independent (canonical) pattern used for displaying date/times in the UI. + * + * <p> + * By default, a locale-specific date/time pattern is used (using {@link java.time.format.FormatStyle#MEDIUM} format) for both the date and time parts. + * </p> + */ + private String dateTimePattern; + } + + @Data public static class TemporalEditingPattern { diff --git a/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/ValueSemanticsAbstract.java b/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/ValueSemanticsAbstract.java index b467d7cab0..4aada99c23 100644 --- a/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/ValueSemanticsAbstract.java +++ b/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/ValueSemanticsAbstract.java @@ -299,20 +299,28 @@ ValueSemanticsProvider<T> { // -- TEMPORAL RENDERING protected DateTimeFormatter getTemporalNoZoneRenderingFormat( - final @Nullable ValueSemanticsProvider.Context context, + final @Nullable Context context, final @NonNull TemporalValueSemantics.TemporalCharacteristic temporalCharacteristic, final @NonNull TemporalValueSemantics.OffsetCharacteristic offsetCharacteristic, final @NonNull FormatStyle dateFormatStyle, - final @NonNull FormatStyle timeFormatStyle) { + final @NonNull FormatStyle timeFormatStyle, + final @Nullable String datePattern, + final @Nullable String dateTimePattern) { final DateTimeFormatter noZoneOutputFormat; switch (temporalCharacteristic) { case DATE_TIME: - noZoneOutputFormat = DateTimeFormatter.ofLocalizedDateTime(dateFormatStyle, timeFormatStyle); + noZoneOutputFormat = + dateTimePattern != null + ? DateTimeFormatter.ofPattern(dateTimePattern) + : DateTimeFormatter.ofLocalizedDateTime(dateFormatStyle, timeFormatStyle); break; case DATE_ONLY: - noZoneOutputFormat = DateTimeFormatter.ofLocalizedDate(dateFormatStyle); + noZoneOutputFormat = + datePattern != null + ? DateTimeFormatter.ofPattern(datePattern) + : DateTimeFormatter.ofLocalizedDate(dateFormatStyle); break; case TIME_ONLY: noZoneOutputFormat = DateTimeFormatter.ofLocalizedTime(timeFormatStyle); diff --git a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java index 95e24c42bf..6ade9786e6 100644 --- a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java +++ b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java @@ -58,6 +58,10 @@ import javax.validation.constraints.Min; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import org.apache.causeway.applib.value.semantics.TemporalValueSemantics; + +import org.apache.causeway.applib.value.semantics.TemporalValueSemantics.TemporalDisplayPattern; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; @@ -3509,6 +3513,7 @@ public class CausewayConfiguration { @Data public static class Temporal { private final TemporalEditingPattern editing = new TemporalEditingPattern(); + private final TemporalDisplayPattern display = new TemporalDisplayPattern(); } private final BigDecimal bigDecimal = new BigDecimal(); diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/valuesemantics/temporal/TemporalValueSemanticsProvider.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/valuesemantics/temporal/TemporalValueSemanticsProvider.java index a97730122c..90d54d2920 100644 --- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/valuesemantics/temporal/TemporalValueSemanticsProvider.java +++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/valuesemantics/temporal/TemporalValueSemanticsProvider.java @@ -205,10 +205,13 @@ implements TemporalValueSemantics<T> { val dateAndTimeFormatStyle = DateAndTimeFormatStyle.forContext(mmc, context); + val datePattern = mmc.getConfiguration().getValueTypes().getTemporal().getDisplay().getDatePattern(); + val dateTimePattern = mmc.getConfiguration().getValueTypes().getTemporal().getDisplay().getDateTimePattern(); val temporalNoZoneRenderingFormat = getTemporalNoZoneRenderingFormat( context, temporalCharacteristic, offsetCharacteristic, dateAndTimeFormatStyle.getDateFormatStyle(), - dateAndTimeFormatStyle.getTimeFormatStyle()); + dateAndTimeFormatStyle.getTimeFormatStyle(), + datePattern, dateTimePattern); val temporalZoneOnlyRenderingFormat = getTemporalZoneOnlyRenderingFormat( context, temporalCharacteristic, offsetCharacteristic).orElse(null); @@ -378,6 +381,7 @@ implements TemporalValueSemantics<T> { .map(ValueSemanticsProvider.Context::getFeatureIdentifier) .orElse(null))); + // DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedPattern(mmc.getConfiguration().getValueTypes().getTemporal().getDisplay().getDatePattern()); val dateFormatStyle = featureIfAny .flatMap(feature->feature.lookupFacet(DateFormatStyleFacet.class)) .map(DateFormatStyleFacet::getDateFormatStyle)
