summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorTatu Lund <tatu@vaadin.com>2020-02-13 09:40:12 +0200
committerGitHub <noreply@github.com>2020-02-13 09:40:12 +0200
commit73db19b6529bf172c3ef484dec0472f3c046fc30 (patch)
treeb740c7c9b632590d2519833984b1a2a138f3a317 /client
parentab3d346c56d8ffee70d1b2b6757ec0fd68d270e1 (diff)
downloadvaadin-framework-73db19b6529bf172c3ef484dec0472f3c046fc30.tar.gz
vaadin-framework-73db19b6529bf172c3ef484dec0472f3c046fc30.zip
Fix logic of lexicographical comparison of DateField range end (#11885)
* Fix logic of lexicographical comparison of DateField range end Fix logic of lexicographical comparison of DateField range end with large year numbers ( > 9999) Fixes #11881 * Added tests Purpose of dateFieldRangeYearDigitsIncrease() is to test that rangeEnd works correctly on 4 to 5 digits change boundary Purpose of dateFieldRangeYearBigNumbersPopupOpens() is to test that popup opens also when there is more than 4 digits in year * Fixing typo * Add error message * Set the date of the field in test * Fixing
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java
index 8fde0264e4..765df8867d 100644
--- a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java
+++ b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java
@@ -762,8 +762,18 @@ public abstract class VAbstractCalendarPanel<R extends Enum<R>>
return true;
}
+ // If dateStrResolution has more year digits than rangeEnd, we need
+ // to pad it in order to be lexicographically compatible
String dateStrResolution = dateStrResolution(date, minResolution);
- return rangeEnd.substring(0, dateStrResolution.length())
+ String paddedEnd = rangeEnd.substring(0);
+ int yearDigits = dateStrResolution.indexOf("-");
+ if (yearDigits == -1) {
+ yearDigits = dateStrResolution.length();
+ }
+ while (paddedEnd.indexOf("-") < yearDigits) {
+ paddedEnd = "0" + paddedEnd;
+ }
+ return paddedEnd.substring(0, dateStrResolution.length())
.compareTo(dateStrResolution) >= 0;
}
@@ -2126,7 +2136,13 @@ public abstract class VAbstractCalendarPanel<R extends Enum<R>>
*/
public void setRangeEnd(String newRangeEnd) {
if (!SharedUtil.equals(rangeEnd, newRangeEnd)) {
- rangeEnd = newRangeEnd;
+ // Dates with year 10000 or more has + prefix, which is not compatible
+ // with format returned by dateStrResolution method
+ if (newRangeEnd.startsWith("+")) {
+ rangeEnd = newRangeEnd.substring(1);
+ } else {
+ rangeEnd = newRangeEnd;
+ }
if (initialRenderDone) {
// Dynamic updates to the range needs to render the calendar to
// update the element stylenames