commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r963601 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/time/DateUtils.java test/java/org/apache/commons/lang3/time/DateUtilsTest.java
Date Tue, 13 Jul 2010 05:17:49 GMT
Author: bayard
Date: Tue Jul 13 05:17:48 2010
New Revision: 963601

URL: http://svn.apache.org/viewvc?rev=963601&view=rev
Log:
Adding toCalendar method per LANG-632

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java?rev=963601&r1=963600&r2=963601&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java Tue
Jul 13 05:17:48 2010
@@ -621,6 +621,20 @@ public class DateUtils {
         c.set(calendarField, amount);
         return c.getTime();
     }   
+
+    //-----------------------------------------------------------------------
+    /**
+     * Convert a Date into a Calendar object. 
+     * 
+     * @param date the date to convert to a Calendar
+     * @return the created Calendar
+     * @throws NullPointerException if null is passed in
+     */
+    public static Calendar toCalendar(Date date) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        return c;
+    }
     
     //-----------------------------------------------------------------------
     /**

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java?rev=963601&r1=963600&r2=963601&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
Tue Jul 13 05:17:48 2010
@@ -598,6 +598,17 @@ public class DateUtilsTest extends TestC
     }
 
     //-----------------------------------------------------------------------
+    public void testToCalendar() {
+        assertEquals("Failed to convert to a Calendar and back", date1, DateUtils.toCalendar(date1).getTime());
+        try {
+            DateUtils.toCalendar(null);
+            fail("Expected NullPointerException to be thrown");
+        } catch(NullPointerException npe) {
+            // expected
+        }
+    }
+
+    //-----------------------------------------------------------------------
     /**
      * Tests various values with the round method
      */



Mime
View raw message