commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: 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 19:48:58 GMT
I am not sure whether this is actually a problem, but I vaguely remember 
that you can have trouble with time zones when converting between dates 
and calendars. I found the following reference [1] which might be helpful.

Oliver

[1] http://www.odi.ch/prog/design/datetime.php

Am 13.07.2010 07:17, schrieb bayard@apache.org:
> 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
>        */
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message