commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1559787 - /commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
Date Mon, 20 Jan 2014 17:33:10 GMT
Author: britter
Date: Mon Jan 20 17:33:09 2014
New Revision: 1559787

URL: http://svn.apache.org/r1559787
Log:
LANG-951: Fragments are wrong by 1 day when using fragment YEAR or MONTH - fix test that failed
because of wrong assertions

Modified:
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java?rev=1559787&r1=1559786&r2=1559787&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
Mon Jan 20 17:33:09 2014
@@ -402,7 +402,7 @@ public class DateUtilsFragmentTest {
     public void testMillisecondsOfMonthWithDate() {
         final long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MONTH);
         assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
-                                + (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY),
+                                + (hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY),
                 testResult);
     }
 
@@ -410,7 +410,7 @@ public class DateUtilsFragmentTest {
     public void testMillisecondsOfMonthWithCalendar() {
         final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MONTH);
         assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
-                + (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY),
+                + (hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY),
 testResult);
     }
     
@@ -420,7 +420,7 @@ testResult);
         assertEquals(
                 seconds
                         + ((minutes * DateUtils.MILLIS_PER_MINUTE)
-                                + (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
+                                + (hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_SECOND,
                 testResult);
     }
@@ -431,7 +431,7 @@ testResult);
         assertEquals(
                 seconds
                         + ((minutes * DateUtils.MILLIS_PER_MINUTE)
-                                + (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
+                                + (hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_SECOND,
                 testResult);
     }
@@ -440,7 +440,7 @@ testResult);
     public void testMinutesOfMonthWithDate() {
         final long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.MONTH);
         assertEquals(minutes
-                                + ((hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
+                                + ((hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_MINUTE,
                 testResult);
     }
@@ -448,7 +448,7 @@ testResult);
     @Test
     public void testMinutesOfMonthWithCalendar() {
         final long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.MONTH);
-        assertEquals( minutes  +((hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
+        assertEquals( minutes  +((hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_MINUTE,
                 testResult);
     }
@@ -456,7 +456,7 @@ testResult);
     @Test
     public void testHoursOfMonthWithDate() {
         final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.MONTH);
-        assertEquals(hours + ((days * DateUtils.MILLIS_PER_DAY))
+        assertEquals(hours + (((days - 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_HOUR,
                 testResult);
     }
@@ -464,7 +464,7 @@ testResult);
     @Test
     public void testHoursOfMonthWithCalendar() {
         final long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.MONTH);
-        assertEquals( hours +((days * DateUtils.MILLIS_PER_DAY))
+        assertEquals( hours +(((days - 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_HOUR,
                 testResult);
     }
@@ -476,7 +476,7 @@ testResult);
         final Calendar cal = Calendar.getInstance();
         cal.setTime(aDate);
         assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
-                                + (hours * DateUtils.MILLIS_PER_HOUR) + (cal.get(Calendar.DAY_OF_YEAR)
* DateUtils.MILLIS_PER_DAY),
+                                + (hours * DateUtils.MILLIS_PER_HOUR) + ((cal.get(Calendar.DAY_OF_YEAR)
- 1)* DateUtils.MILLIS_PER_DAY),
                 testResult);
     }
 
@@ -484,7 +484,7 @@ testResult);
     public void testMillisecondsOfYearWithCalendar() {
         final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.YEAR);
         assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
-                + (hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR)
* DateUtils.MILLIS_PER_DAY),
+                + (hours * DateUtils.MILLIS_PER_HOUR) + ((aCalendar.get(Calendar.DAY_OF_YEAR)
- 1) * DateUtils.MILLIS_PER_DAY),
 testResult);
     }
     
@@ -496,7 +496,7 @@ testResult);
         assertEquals(
                 seconds
                         + ((minutes * DateUtils.MILLIS_PER_MINUTE)
-                                + (hours * DateUtils.MILLIS_PER_HOUR) + (cal.get(Calendar.DAY_OF_YEAR)
* DateUtils.MILLIS_PER_DAY))
+                                + (hours * DateUtils.MILLIS_PER_HOUR) + ((cal.get(Calendar.DAY_OF_YEAR)
- 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_SECOND,
                 testResult);
     }
@@ -507,7 +507,7 @@ testResult);
         assertEquals(
                 seconds
                         + ((minutes * DateUtils.MILLIS_PER_MINUTE)
-                                + (hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR)
* DateUtils.MILLIS_PER_DAY))
+                                + (hours * DateUtils.MILLIS_PER_HOUR) + ((aCalendar.get(Calendar.DAY_OF_YEAR)
- 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_SECOND,
                 testResult);
     }
@@ -518,7 +518,7 @@ testResult);
         final Calendar cal = Calendar.getInstance();
         cal.setTime(aDate);
         assertEquals(minutes
-                                + ((hours * DateUtils.MILLIS_PER_HOUR) + (cal.get(Calendar.DAY_OF_YEAR)
* DateUtils.MILLIS_PER_DAY))
+                                + ((hours * DateUtils.MILLIS_PER_HOUR) + ((cal.get(Calendar.DAY_OF_YEAR)
- 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_MINUTE,
                 testResult);
     }
@@ -526,7 +526,7 @@ testResult);
     @Test
     public void testMinutesOfYearWithCalendar() {
         final long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.YEAR);
-        assertEquals( minutes  +((hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR)
* DateUtils.MILLIS_PER_DAY))
+        assertEquals( minutes  +((hours * DateUtils.MILLIS_PER_HOUR) + ((aCalendar.get(Calendar.DAY_OF_YEAR)
- 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_MINUTE,
                 testResult);
     }
@@ -549,7 +549,7 @@ testResult);
         final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR);
         final Calendar cal = Calendar.getInstance();
         cal.setTime(aDate);
-        assertEquals(hours + ((cal.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
+        assertEquals(hours + (((cal.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_HOUR,
                 testResult);
     }
@@ -557,7 +557,7 @@ testResult);
     @Test
     public void testHoursOfYearWithCalendar() {
         final long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.YEAR);
-        assertEquals( hours +((aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
+        assertEquals( hours +(((aCalendar.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY))
                         / DateUtils.MILLIS_PER_HOUR,
                 testResult);
     }



Mime
View raw message