empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From franci...@apache.org
Subject svn commit: r1507990 - in /empire-db/trunk/empire-db/src: main/java/org/apache/empire/commons/DateUtils.java test/java/org/apache/empire/commons/DateUtilsTest.java
Date Mon, 29 Jul 2013 09:58:51 GMT
Author: francisdb
Date: Mon Jul 29 09:58:50 2013
New Revision: 1507990

URL: http://svn.apache.org/r1507990
Log:
fix EMPIREDB-187 - DateUtilsTest fails on specific dates + code it is testing is not used

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/DateUtils.java
    empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/DateUtilsTest.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/DateUtils.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/DateUtils.java?rev=1507990&r1=1507989&r2=1507990&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/DateUtils.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/DateUtils.java Mon Jul
29 09:58:50 2013
@@ -34,7 +34,6 @@ import org.slf4j.LoggerFactory;
  */
 public class DateUtils
 {
-    // Logger
     private static final Logger log = LoggerFactory.getLogger(DateUtils.class);
     
     private DateUtils()
@@ -42,36 +41,6 @@ public class DateUtils
         // Static Function only
         // No instance may be created
     }
-        
-    /**
-     * returns a date relative from the current date.
-     * <P>
-     * @param withTime true if the current time should be added or false if only the date
is desired.
-     * @param years number of years to add or subtract from the current date
-     * @param months number of months to add or subtract from the current date
-     * @param days number of days to add or subtract from the current date
-     * @return the target date
-     */
-    public static Date getDateTimeFromNow(boolean withTime, int years, int months, int days)
-    {
-        Calendar calendar = Calendar.getInstance();
-        if (withTime==false)
-        {
-            calendar.set(Calendar.HOUR_OF_DAY, 0);
-            calendar.set(Calendar.MINUTE, 0);
-            calendar.set(Calendar.SECOND, 0);
-            calendar.set(Calendar.MILLISECOND, 0);
-        }
-        // Roll
-        if (years!=0)
-            calendar.add(Calendar.YEAR, years);
-        if (months!=0)
-            calendar.add(Calendar.MONTH, months);
-        if (days!=0)
-            calendar.add(Calendar.DAY_OF_MONTH, days);
-        // get Time
-        return calendar.getTime();
-    }
 
     /**
      * Returns the current date without time
@@ -79,7 +48,12 @@ public class DateUtils
      */
     public static Date getDateNow()
     {
-        return getDateTimeFromNow(false, 0, 0, 0);
+    	Calendar calendar = Calendar.getInstance();
+	    calendar.set(Calendar.HOUR_OF_DAY, 0);
+	    calendar.set(Calendar.MINUTE, 0);
+	    calendar.set(Calendar.SECOND, 0);
+	    calendar.set(Calendar.MILLISECOND, 0);
+	    return calendar.getTime();
     }
 
     /**
@@ -88,7 +62,7 @@ public class DateUtils
      */
     public static Date getTimeNow()
     {
-        return getDateTimeFromNow(true, 0, 0, 0);
+        return Calendar.getInstance().getTime();
     }
 
     /**
@@ -244,4 +218,24 @@ public class DateUtils
         c.setTime(d);
         return sdf.format(d);
     }
+    
+    
+	/**
+	 * returns a date relative from the current date.
+	 * <P>
+	 * @param withTime true if the current time should be added or false if only the date is
desired.
+	 * @return the target date
+	 */
+	private static Date getDateTimeFromNow(boolean withTime)
+	{
+	    Calendar calendar = Calendar.getInstance();
+	    if (withTime==false)
+	    {
+	        calendar.set(Calendar.HOUR_OF_DAY, 0);
+	        calendar.set(Calendar.MINUTE, 0);
+	        calendar.set(Calendar.SECOND, 0);
+	        calendar.set(Calendar.MILLISECOND, 0);
+	    }
+	    return calendar.getTime();
+	}
 }

Modified: empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/DateUtilsTest.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/DateUtilsTest.java?rev=1507990&r1=1507989&r2=1507990&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/DateUtilsTest.java (original)
+++ empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/DateUtilsTest.java Mon
Jul 29 09:58:50 2013
@@ -33,26 +33,6 @@ import org.junit.Test;
  */
 public class DateUtilsTest
 {
-	
-	/**
-	 * Test method for {@link org.apache.empire.commons.DateUtils#getDateTimeFromNow(boolean,
int, int, int)}.
-	 */
-	@Test
-	public void testGetDateTimeFromNow()
-	{
-		Calendar now = Calendar.getInstance();
-		Date date = DateUtils.getDateTimeFromNow(false, 1, 2, 3);
-		Calendar future = Calendar.getInstance();
-		future.setTime(date);
-		future.add(Calendar.YEAR, -1);
-		future.add(Calendar.MONTH, -2);
-		future.add(Calendar.DAY_OF_MONTH, -3);
-
-		// this might fail when running exacly over midnight...
-		assertEquals(now.get(Calendar.YEAR), future.get(Calendar.YEAR));
-		assertEquals(now.get(Calendar.MONTH), future.get(Calendar.MONTH));
-		assertEquals(now.get(Calendar.DAY_OF_MONTH), future.get(Calendar.DAY_OF_MONTH));
-	}
 
 	/**
 	 * Test method for {@link org.apache.empire.commons.DateUtils#getDateNow()}.



Mime
View raw message