diff options
author | elmot <elmotelmot.vaadin.com> | 2017-07-27 08:28:49 +0300 |
---|---|---|
committer | elmot <elmotelmot.vaadin.com> | 2017-07-27 08:28:49 +0300 |
commit | 0517853905c10f5594adf799d9664f96bb863d78 (patch) | |
tree | 2f4a950f5eedb152f8e67598e3e286c6ceef78b4 | |
parent | 648b8db5e174a267feafcc0cadce12fb5238414c (diff) | |
download | vaadin-framework-0517853905c10f5594adf799d9664f96bb863d78.tar.gz vaadin-framework-0517853905c10f5594adf799d9664f96bb863d78.zip |
Forgotten change
3 files changed, 45 insertions, 18 deletions
diff --git a/server/src/main/java/com/vaadin/ui/AbstractLocalDateField.java b/server/src/main/java/com/vaadin/ui/AbstractLocalDateField.java index 7754757429..2fdf2bf382 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractLocalDateField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractLocalDateField.java @@ -18,7 +18,10 @@ package com.vaadin.ui; import java.time.Instant; import java.time.LocalDate; import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; import java.util.Date; +import java.util.Locale; import java.util.Map; import com.vaadin.data.validator.DateRangeValidator; @@ -28,11 +31,9 @@ import com.vaadin.shared.ui.datefield.DateResolution; /** * Abstract DateField class for {@link LocalDate} type. - * + * * @author Vaadin Ltd - * * @since 8.0 - * */ public abstract class AbstractLocalDateField extends AbstractDateField<LocalDate, DateResolution> { @@ -47,8 +48,7 @@ public abstract class AbstractLocalDateField /** * Constructs an empty <code>AbstractLocalDateField</code> with caption. * - * @param caption - * the caption of the datefield. + * @param caption the caption of the datefield. */ public AbstractLocalDateField(String caption) { super(caption, DateResolution.DAY); @@ -58,10 +58,8 @@ public abstract class AbstractLocalDateField * Constructs a new <code>AbstractLocalDateField</code> with the given * caption and initial text contents. * - * @param caption - * the caption <code>String</code> for the editor. - * @param value - * the LocalDate value. + * @param caption the caption <code>String</code> for the editor. + * @param value the LocalDate value. */ public AbstractLocalDateField(String caption, LocalDate value) { super(caption, value, DateResolution.DAY); @@ -74,15 +72,15 @@ public abstract class AbstractLocalDateField value = LocalDate.of(1, 1, 1); } switch (resolution) { - case DAY: - return value.getDayOfMonth(); - case MONTH: - return value.getMonthValue(); - case YEAR: - return value.getYear(); - default: - assert false : "Unexpected resolution argument " + resolution; - return -1; + case DAY: + return value.getDayOfMonth(); + case MONTH: + return value.getMonthValue(); + case YEAR: + return value.getYear(); + default: + assert false : "Unexpected resolution argument " + resolution; + return -1; } } @@ -140,4 +138,15 @@ public abstract class AbstractLocalDateField return date; } } + + @Override + protected String formatDate(LocalDate value) { + if (value == null) return ""; + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); + Locale locale = getLocale(); + if (locale != null){ + dateTimeFormatter = dateTimeFormatter.withLocale(locale); + } + return value.format(dateTimeFormatter); + } } diff --git a/server/src/main/java/com/vaadin/ui/AbstractLocalDateTimeField.java b/server/src/main/java/com/vaadin/ui/AbstractLocalDateTimeField.java index 65da2a2b8b..1e036f371b 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractLocalDateTimeField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractLocalDateTimeField.java @@ -16,10 +16,14 @@ package com.vaadin.ui; import java.time.Instant; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; import java.time.temporal.ChronoUnit; import java.util.Date; +import java.util.Locale; import java.util.Map; import com.vaadin.data.validator.DateTimeRangeValidator; @@ -163,4 +167,14 @@ public abstract class AbstractLocalDateTimeField } } + @Override + protected String formatDate(LocalDateTime value) { + if (value == null) return ""; + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); + Locale locale = getLocale(); + if (locale != null) { + dateTimeFormatter = dateTimeFormatter.withLocale(locale); + } + return value.format(dateTimeFormatter); + } } diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java index cab1addf58..508243964d 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java @@ -50,6 +50,10 @@ public class DateFieldListenersTest extends AbstractListenerMethodsTestBase { return null; } + @Override + protected String formatDate(T value) { + return value.toString(); + } } @Test |