You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2016/10/02 10:28:31 UTC
[1/6] [lang] Add DateUtils.toCalendar(Date, TimeZone)
Repository: commons-lang
Updated Branches:
refs/heads/master 86a59601b -> 33bb9fe25
Add DateUtils.toCalendar(Date, TimeZone)
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/1eecfc94
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/1eecfc94
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/1eecfc94
Branch: refs/heads/master
Commit: 1eecfc948bf6f4cbb9a2481313ca7368ec653056
Parents: db6f7c1
Author: Kaiyuan Wang <wa...@gmail.com>
Authored: Tue Sep 20 23:58:36 2016 -0500
Committer: Kaiyuan Wang <wa...@gmail.com>
Committed: Tue Sep 20 23:58:36 2016 -0500
----------------------------------------------------------------------
.../java/org/apache/commons/lang3/time/DateUtils.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/1eecfc94/src/main/java/org/apache/commons/lang3/time/DateUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
index c242bd5..e9ae23f 100644
--- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
@@ -668,6 +668,19 @@ public class DateUtils {
//-----------------------------------------------------------------------
/**
+ * Converts a {@code Date} of a given {@code TimeZone} into a {@code Calendar}
+ * @param date the date to convert to a Calendar
+ * @param timeZone the time zone of the @{code date}
+ * @return
+ */
+ public static Calendar toCalendar(final Date date, final TimeZone tz) {
+ final Calendar c = Calendar.getInstance(tz);
+ c.setTime(date);
+ return c;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* <p>Rounds a date, leaving the field specified as the most
* significant field.</p>
*
[4/6] [lang] Handle Comments
Posted by br...@apache.org.
Handle Comments
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/8ac857c4
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/8ac857c4
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/8ac857c4
Branch: refs/heads/master
Commit: 8ac857c41ec8ae02e57eb0c1c1a012525e7e14b9
Parents: d9a2c69
Author: Kaiyuan Wang <wa...@gmail.com>
Authored: Sun Sep 25 13:13:03 2016 -0500
Committer: Kaiyuan Wang <wa...@gmail.com>
Committed: Sun Sep 25 13:13:03 2016 -0500
----------------------------------------------------------------------
.../commons/lang3/time/DateUtilsTest.java | 45 ++++----------------
1 file changed, 9 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/8ac857c4/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
index d4d1917..bb6e59f 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
@@ -695,56 +695,29 @@ public class DateUtilsTest {
}
//-----------------------------------------------------------------------
- @Test
- public void testToCalendarWithDateNotNull() {
- assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date1, DateUtils.toCalendar(date1, zone).getTime());
- }
-
- //-----------------------------------------------------------------------
- @Test
+ @Test(expected=NullPointerException.class)
public void testToCalendarWithDateNull() {
- try {
- DateUtils.toCalendar(null, zone);
- fail("Expected NullPointerException to be thrown when Date is null");
- } catch(final NullPointerException npe) {
- // expected
- }
- }
-
- //-----------------------------------------------------------------------
- @Test
- public void testToCalendarWithTimeZoneNotNull() {
- assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", zone, DateUtils.toCalendar(date1, zone).getTimeZone());
+ DateUtils.toCalendar(null, zone);
}
//-----------------------------------------------------------------------
- @Test
+ @Test(expected=NullPointerException.class)
public void testToCalendarWithTimeZoneNull() {
- try {
- DateUtils.toCalendar(date1, null);
- fail("Expected NullPointerException to be thrown when TimeZone is null");
- } catch(final NullPointerException npe) {
- // expected
- }
+ DateUtils.toCalendar(date1, null);
}
//-----------------------------------------------------------------------
@Test
public void testToCalendarWithDateAndTimeZoneNotNull() {
- Calendar c = DateUtils.toCalendar(date2, defaultZone);
- assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date2, c.getTime());
- assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", defaultZone, c.getTimeZone());
+ Calendar c = DateUtils.toCalendar(date2, defaultZone);
+ assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date2, c.getTime());
+ assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", defaultZone, c.getTimeZone());
}
//-----------------------------------------------------------------------
- @Test
+ @Test(expected=NullPointerException.class)
public void testToCalendarWithDateAndTimeZoneNull() {
- try {
- DateUtils.toCalendar(null, null);
- fail("Expected NullPointerException to be thrown when both Date and TimeZone are null");
- } catch(final NullPointerException npe) {
- // expected
- }
+ DateUtils.toCalendar(null, null);
}
//-----------------------------------------------------------------------
[2/6] [lang] Add unit tests for DateUtils.toCalendar(Date, TimeZone)
Posted by br...@apache.org.
Add unit tests for DateUtils.toCalendar(Date, TimeZone)
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/ac5a216f
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/ac5a216f
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/ac5a216f
Branch: refs/heads/master
Commit: ac5a216f767c6defa4da720c6ecb3baa05e30254
Parents: 1eecfc9
Author: Kaiyuan Wang <wa...@gmail.com>
Authored: Tue Sep 20 23:59:04 2016 -0500
Committer: Kaiyuan Wang <wa...@gmail.com>
Committed: Tue Sep 20 23:59:04 2016 -0500
----------------------------------------------------------------------
.../commons/lang3/time/DateUtilsTest.java | 37 ++++++++++++++++++++
1 file changed, 37 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/ac5a216f/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
index 0b80ab6..280d681 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
@@ -693,6 +693,43 @@ public class DateUtilsTest {
// expected
}
}
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testToCalendarWithDate() {
+ assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date1, DateUtils.toCalendar(date1, zone).getTime());
+ try {
+ DateUtils.toCalendar(null, zone);
+ fail("Expected NullPointerException to be thrown");
+ } catch(final NullPointerException npe) {
+ // expected
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testToCalendarWithTimeZone() {
+ assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", zone, DateUtils.toCalendar(date1, zone).getTimeZone());
+ try {
+ DateUtils.toCalendar(date1, null);
+ fail("Expected NullPointerException to be thrown");
+ } catch(final NullPointerException npe) {
+ // expected
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testToCalendarWithDateAndTimeZone() {
+ try {
+ Calendar c = DateUtils.toCalendar(date2, defaultZone);
+ assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date2, c.getTime());
+ assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", defaultZone, c.getTimeZone());
+ // expected
+ } catch(final NullPointerException npe) {
+ fail("Expected NullPointerException to be thrown");
+ }
+ }
//-----------------------------------------------------------------------
/**
[6/6] [lang] Merge branch 'LANG-1255'
Posted by br...@apache.org.
Merge branch 'LANG-1255'
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/33bb9fe2
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/33bb9fe2
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/33bb9fe2
Branch: refs/heads/master
Commit: 33bb9fe25b9200e75cc4bf2483b17a35df960034
Parents: 86a5960 9209e23
Author: Benedikt Ritter <br...@apache.org>
Authored: Sun Oct 2 12:28:09 2016 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Sun Oct 2 12:28:09 2016 +0200
----------------------------------------------------------------------
src/changes/changes.xml | 1 +
.../apache/commons/lang3/time/DateUtils.java | 14 +++++++++++
.../commons/lang3/time/DateUtilsTest.java | 26 ++++++++++++++++++++
3 files changed, 41 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/33bb9fe2/src/changes/changes.xml
----------------------------------------------------------------------
diff --cc src/changes/changes.xml
index dde81f6,8a9861e..39a2d27
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@@ -46,8 -46,7 +46,9 @@@ The <action> type attribute can be add,
<body>
<release version="3.5" date="tba" description="New features including Java 9 detection">
+ <action issue="LANG-1255" type="add" dev="britter" due-to="Kaiyuan Wang">Add DateUtils.toCalendar(Date, TimeZone)</action>
+ <action issue="LANG-1023" type="add" dev="britter" due-to="Marko Bekhta">Add WordUtils.wrap overload with customizable breakable character</action>
+ <action issue="LANG-787" type="add" dev="pschumacher" due-to="Gokul Nanthakumar C">Add method removeIgnoreCase(String, String) to StringUtils</action>
<action issue="LANG-1261" type="fix" dev="pschumacher" >ArrayUtils.contains returns false for instances of subtypes</action>
<action issue="LANG-1197" type="update" dev="pschumacher" >Prepare Java 9 detection</action>
<action issue="LANG-1252" type="fix" dev="chtompki" due-to="Rob Tompkins">Rename NumberUtils.isNumber, isCreatable to better reflect createNumber. Also, accommodated for "+" symbol as prefix in isCreatable and isNumber.</action>
[5/6] [lang] Add LANG-1255 to changes.xml
Posted by br...@apache.org.
Add LANG-1255 to changes.xml
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/9209e235
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/9209e235
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/9209e235
Branch: refs/heads/master
Commit: 9209e235a57d1b801b5da527b298f6387e311b34
Parents: 8ac857c
Author: Benedikt Ritter <br...@apache.org>
Authored: Sun Oct 2 12:26:19 2016 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Sun Oct 2 12:26:19 2016 +0200
----------------------------------------------------------------------
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9209e235/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index bc720f7..8a9861e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="3.5" date="tba" description="New features including Java 9 detection">
+ <action issue="LANG-1255" type="add" dev="britter" due-to="Kaiyuan Wang">Add DateUtils.toCalendar(Date, TimeZone)</action>
<action issue="LANG-1261" type="fix" dev="pschumacher" >ArrayUtils.contains returns false for instances of subtypes</action>
<action issue="LANG-1197" type="update" dev="pschumacher" >Prepare Java 9 detection</action>
<action issue="LANG-1252" type="fix" dev="chtompki" due-to="Rob Tompkins">Rename NumberUtils.isNumber, isCreatable to better reflect createNumber. Also, accommodated for "+" symbol as prefix in isCreatable and isNumber.</action>
[3/6] [lang] Handle Benedikt Ritter's comments
Posted by br...@apache.org.
Handle Benedikt Ritter's comments
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/d9a2c69a
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/d9a2c69a
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/d9a2c69a
Branch: refs/heads/master
Commit: d9a2c69a9d1db6072e1d7b7ea4fcbd5c15d20b5d
Parents: ac5a216
Author: Kaiyuan Wang <wa...@gmail.com>
Authored: Sat Sep 24 10:01:41 2016 -0500
Committer: Kaiyuan Wang <wa...@gmail.com>
Committed: Sat Sep 24 10:01:41 2016 -0500
----------------------------------------------------------------------
.../apache/commons/lang3/time/DateUtils.java | 5 ++-
.../commons/lang3/time/DateUtilsTest.java | 40 ++++++++++++++------
2 files changed, 31 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/d9a2c69a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
index e9ae23f..8349c25 100644
--- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
@@ -670,8 +670,9 @@ public class DateUtils {
/**
* Converts a {@code Date} of a given {@code TimeZone} into a {@code Calendar}
* @param date the date to convert to a Calendar
- * @param timeZone the time zone of the @{code date}
- * @return
+ * @param tz the time zone of the @{code date}
+ * @return the created Calendar
+ * @throws NullPointerException if {@code date} or {@code tz} is null
*/
public static Calendar toCalendar(final Date date, final TimeZone tz) {
final Calendar c = Calendar.getInstance(tz);
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/d9a2c69a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
index 280d681..d4d1917 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
@@ -696,11 +696,16 @@ public class DateUtilsTest {
//-----------------------------------------------------------------------
@Test
- public void testToCalendarWithDate() {
+ public void testToCalendarWithDateNotNull() {
assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date1, DateUtils.toCalendar(date1, zone).getTime());
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testToCalendarWithDateNull() {
try {
DateUtils.toCalendar(null, zone);
- fail("Expected NullPointerException to be thrown");
+ fail("Expected NullPointerException to be thrown when Date is null");
} catch(final NullPointerException npe) {
// expected
}
@@ -708,26 +713,37 @@ public class DateUtilsTest {
//-----------------------------------------------------------------------
@Test
- public void testToCalendarWithTimeZone() {
+ public void testToCalendarWithTimeZoneNotNull() {
assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", zone, DateUtils.toCalendar(date1, zone).getTimeZone());
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testToCalendarWithTimeZoneNull() {
try {
DateUtils.toCalendar(date1, null);
- fail("Expected NullPointerException to be thrown");
+ fail("Expected NullPointerException to be thrown when TimeZone is null");
} catch(final NullPointerException npe) {
// expected
}
}
- //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
@Test
- public void testToCalendarWithDateAndTimeZone() {
- try {
- Calendar c = DateUtils.toCalendar(date2, defaultZone);
- assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date2, c.getTime());
- assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", defaultZone, c.getTimeZone());
- // expected
+ public void testToCalendarWithDateAndTimeZoneNotNull() {
+ Calendar c = DateUtils.toCalendar(date2, defaultZone);
+ assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date2, c.getTime());
+ assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", defaultZone, c.getTimeZone());
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testToCalendarWithDateAndTimeZoneNull() {
+ try {
+ DateUtils.toCalendar(null, null);
+ fail("Expected NullPointerException to be thrown when both Date and TimeZone are null");
} catch(final NullPointerException npe) {
- fail("Expected NullPointerException to be thrown");
+ // expected
}
}