commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang/time DateUtils.java
Date Wed, 13 Oct 2004 21:48:00 GMT
scolebourne    2004/10/13 14:48:00

  Modified:    lang/src/test/org/apache/commons/lang/time
                        DateUtilsTest.java
               lang/src/java/org/apache/commons/lang/time DateUtils.java
  Log:
  Add Date equivalent of isSameDay method
  
  Revision  Changes    Path
  1.18      +14 -1     jakarta-commons/lang/src/test/org/apache/commons/lang/time/DateUtilsTest.java
  
  Index: DateUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/time/DateUtilsTest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- DateUtilsTest.java	7 Sep 2004 23:03:37 -0000	1.17
  +++ DateUtilsTest.java	13 Oct 2004 21:48:00 -0000	1.18
  @@ -153,7 +153,20 @@
       }
       
       //-----------------------------------------------------------------------
  -    public void testIsSameDay() {
  +    public void testIsSameDay_Date() {
  +        Date date1 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
  +        Date date2 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
  +        assertEquals(true, DateUtils.isSameDay(date1, date2));
  +        date2 = new GregorianCalendar(2004, 6, 10, 13, 45).getTime();
  +        assertEquals(false, DateUtils.isSameDay(date1, date2));
  +        date1 = new GregorianCalendar(2004, 6, 10, 13, 45).getTime();
  +        assertEquals(true, DateUtils.isSameDay(date1, date2));
  +        date2 = new GregorianCalendar(2005, 6, 10, 13, 45).getTime();
  +        assertEquals(false, DateUtils.isSameDay(date1, date2));
  +    }
  +    
  +    //-----------------------------------------------------------------------
  +    public void testIsSameDay_Cal() {
           GregorianCalendar cal1 = new GregorianCalendar(2004, 6, 9, 13, 45);
           GregorianCalendar cal2 = new GregorianCalendar(2004, 6, 9, 13, 45);
           assertEquals(true, DateUtils.isSameDay(cal1, cal2));
  
  
  
  1.32      +26 -1     jakarta-commons/lang/src/java/org/apache/commons/lang/time/DateUtils.java
  
  Index: DateUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/time/DateUtils.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- DateUtils.java	8 Oct 2004 00:09:01 -0000	1.31
  +++ DateUtils.java	13 Oct 2004 21:48:00 -0000	1.32
  @@ -119,6 +119,31 @@
   
       //-----------------------------------------------------------------------
       /**
  +     * <p>Checks if two date objects are on the same day ignoring time.</p>
  +     *
  +     * <p>28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true.
  +     * 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false.
  +     * </p>
  +     * 
  +     * @param date1  the first date, not null
  +     * @param date2  the second date, not null
  +     * @return true if they represent the same day
  +     * @throws IllegalArgumentException if either date is <code>null</code>
  +     * @since 2.1
  +     */
  +    public static boolean isSameDay(Date date1, Date date2) {
  +        if (date1 == null || date2 == null) {
  +            throw new IllegalArgumentException("The date must not be null");
  +        }
  +        Calendar cal1 = Calendar.getInstance();
  +        cal1.setTime(date1);
  +        Calendar cal2 = Calendar.getInstance();
  +        cal2.setTime(date2);
  +        return isSameDay(cal1, cal2);
  +    }
  +
  +    //-----------------------------------------------------------------------
  +    /**
        * <p>Checks if two calendar objects are on the same day ignoring time.</p>
        *
        * <p>28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true.
  
  
  

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


Mime
View raw message