Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Furnadjiev2017-03-21 08:54:02 +0000
committerIvan Furnadjiev2017-03-21 09:43:24 +0000
commitd4d6c5186f6477eeb7810d967cd2f96cc744be9c (patch)
tree271beec90ff9dd91f31b2033f9e1f3288feb41fd
parentb0ef7d2f459d707b5182b7ac231aa7911eb01305 (diff)
downloadorg.eclipse.rap-d4d6c5186f6477eeb7810d967cd2f96cc744be9c.tar.gz
org.eclipse.rap-d4d6c5186f6477eeb7810d967cd2f96cc744be9c.tar.xz
org.eclipse.rap-d4d6c5186f6477eeb7810d967cd2f96cc744be9c.zip
Create a safe-copy of min/max date in setters and getters
To avoid min/max date manipulation outside the DateTime widget, the min/max setters and getters should create a safe-copy of the Date object. Change-Id: I19705fd401e91b5b1f3b6c60e0f26a05184dbd58
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/DateTime.java18
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DateTime_Test.java58
2 files changed, 62 insertions, 14 deletions
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/DateTime.java
index f58e686eea..12400fbc56 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/DateTime.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/DateTime.java
@@ -420,7 +420,7 @@ public class DateTime extends Composite {
*/
public Date getMinimum() {
checkWidget();
- return minimum;
+ return minimum == null ? null : ( Date )minimum.clone();
}
/**
@@ -437,7 +437,7 @@ public class DateTime extends Composite {
*/
public Date getMaximum() {
checkWidget();
- return maximum;
+ return maximum == null ? null : ( Date )maximum.clone();
}
/**
@@ -594,8 +594,11 @@ public class DateTime extends Composite {
*/
public void setMinimum( Date date ) {
checkWidget();
- if( date == null || maximum == null || date.getTime() < maximum.getTime() ) {
- minimum = date;
+ if( date == null ) {
+ minimum = null;
+ applyLimits();
+ } else if( maximum == null || date.getTime() < maximum.getTime() ) {
+ minimum = ( Date )date.clone();
applyLimits();
}
}
@@ -615,8 +618,11 @@ public class DateTime extends Composite {
*/
public void setMaximum( Date date ) {
checkWidget();
- if( date == null || minimum == null || date.getTime() > minimum.getTime() ) {
- maximum = date;
+ if( date == null ) {
+ maximum = null;
+ applyLimits();
+ } else if( minimum == null || date.getTime() > minimum.getTime() ) {
+ maximum = ( Date )date.clone();
applyLimits();
}
}
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DateTime_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DateTime_Test.java
index 56b3b0ad2d..2e790e403a 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DateTime_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DateTime_Test.java
@@ -43,6 +43,8 @@ import org.junit.Test;
public class DateTime_Test {
+ private static long WEEK_TIME = 7 * 24 * 60 * 60 * 1000;
+
@Rule
public TestContext context = new TestContext();
@@ -132,7 +134,7 @@ public class DateTime_Test {
}
@Test
- public void testSetMininum() throws ParseException {
+ public void testSetMinimum() throws ParseException {
Date minimum = formatter.parse( "1985-10-29 11:00:00" );
dateTime.setMinimum( minimum );
@@ -141,7 +143,7 @@ public class DateTime_Test {
}
@Test
- public void testSetMininum_limitsDate() throws ParseException {
+ public void testSetMinimum_limitsDate() throws ParseException {
dateTime.setDate( 1984, 8, 28 );
dateTime.setMinimum( formatter.parse( "1985-10-29 11:00:00" ) );
@@ -151,7 +153,7 @@ public class DateTime_Test {
}
@Test
- public void testSetMininum_limitsYear() throws ParseException {
+ public void testSetMinimum_limitsYear() throws ParseException {
dateTime.setMinimum( formatter.parse( "1985-10-29 11:00:00" ) );
dateTime.setDate( 1984, 10, 29 );
@@ -161,7 +163,7 @@ public class DateTime_Test {
}
@Test
- public void testSetMininum_limitsMonth() throws ParseException {
+ public void testSetMinimum_limitsMonth() throws ParseException {
dateTime.setMinimum( formatter.parse( "1985-10-29 11:00:00" ) );
dateTime.setDate( 1985, 5, 29 );
@@ -171,7 +173,7 @@ public class DateTime_Test {
}
@Test
- public void testSetMininum_limitsDay() throws ParseException {
+ public void testSetMinimum_limitsDay() throws ParseException {
dateTime.setMinimum( formatter.parse( "1985-10-29 11:00:00" ) );
dateTime.setDate( 1985, 9, 28 );
@@ -181,7 +183,7 @@ public class DateTime_Test {
}
@Test
- public void testSetMininum_limitsHour() throws ParseException {
+ public void testSetMinimum_limitsHour() throws ParseException {
dateTime.setMinimum( formatter.parse( "1985-10-29 11:22:33" ) );
dateTime.setDate( 1985, 9, 28 );
dateTime.setTime( 10, 22, 33 );
@@ -192,7 +194,7 @@ public class DateTime_Test {
}
@Test
- public void testSetMininum_limitsMinute() throws ParseException {
+ public void testSetMinimum_limitsMinute() throws ParseException {
dateTime.setMinimum( formatter.parse( "1985-10-29 11:22:33" ) );
dateTime.setDate( 1985, 9, 28 );
dateTime.setTime( 11, 21, 33 );
@@ -203,7 +205,7 @@ public class DateTime_Test {
}
@Test
- public void testSetMininum_limitsSecond() throws ParseException {
+ public void testSetMinimum_limitsSecond() throws ParseException {
dateTime.setMinimum( formatter.parse( "1985-10-29 11:22:33" ) );
dateTime.setDate( 1985, 9, 28 );
dateTime.setTime( 11, 22, 32 );
@@ -214,6 +216,26 @@ public class DateTime_Test {
}
@Test
+ public void testSetMinimum_createsSafeCopy() throws ParseException {
+ Date minimum = formatter.parse( "1985-10-10 11:22:33" );
+ dateTime.setMinimum( minimum );
+
+ minimum.setTime( minimum.getTime() + WEEK_TIME );
+
+ assertEquals( formatter.parse( "1985-10-10 11:22:33" ), dateTime.getMinimum() );
+ }
+
+ @Test
+ public void testGetMinimum_returnsSafeCopy() throws ParseException {
+ dateTime.setMinimum( formatter.parse( "1985-10-10 11:22:33" ) );
+ Date minimum = dateTime.getMinimum();
+
+ minimum.setTime( minimum.getTime() + WEEK_TIME );
+
+ assertEquals( formatter.parse( "1985-10-10 11:22:33" ), dateTime.getMinimum() );
+ }
+
+ @Test
public void testSetMaximum() throws ParseException {
Date maximum = formatter.parse( "2020-03-15 11:00:00" );
@@ -296,6 +318,26 @@ public class DateTime_Test {
}
@Test
+ public void testSetMaximum_createsSafeCopy() throws ParseException {
+ Date maximum = formatter.parse( "1985-10-10 11:22:33" );
+ dateTime.setMaximum( maximum );
+
+ maximum.setTime( maximum.getTime() + WEEK_TIME );
+
+ assertEquals( formatter.parse( "1985-10-10 11:22:33" ), dateTime.getMaximum() );
+ }
+
+ @Test
+ public void testGetMaximum_returnsSafeCopy() throws ParseException {
+ dateTime.setMaximum( formatter.parse( "1985-10-10 11:22:33" ) );
+ Date maximum = dateTime.getMaximum();
+
+ maximum.setTime( maximum.getTime() + WEEK_TIME );
+
+ assertEquals( formatter.parse( "1985-10-10 11:22:33" ), dateTime.getMaximum() );
+ }
+
+ @Test
public void testSetDate() {
dateTime.setDate( 1985, 10, 29 );
assertEquals( 29, dateTime.getDay() );

Back to the top