commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1559780 - in /commons/proper/lang/trunk/src: changes/changes.xml main/java/org/apache/commons/lang3/time/DateUtils.java test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
Date Mon, 20 Jan 2014 17:20:00 GMT
Author: britter
Date: Mon Jan 20 17:19:59 2014
New Revision: 1559780

URL: http://svn.apache.org/r1559780
Log:
LANG-951: Fragments are wrong by 1 day when using fragment YEAR or MONTH - applying patch
provided by Sebastian Götz, several tests now fail because of wrong assertions, will fix
them in a separate commit

Modified:
    commons/proper/lang/trunk/src/changes/changes.xml
    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/DateUtilsFragmentTest.java

Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1559780&r1=1559779&r2=1559780&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Mon Jan 20 17:19:59 2014
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.3" date="TBA" description="Bugfix and Feature release">
+    <action issue="LANG-951" type="fix" dev="britter" due-to="Sebastian Götz">Fragments
are wrong by 1 day when using fragment YEAR or MONTH</action>
     <action issue="LANG-417" type="add" dev="britter">New class ClassPathUtils with
methods for turning FQN into resource path</action>
     <action issue="LANG-939" type="update" dev="britter">Move Documentation from user
guide to package-info files</action>
     <action issue="LANG-953" type="update" dev="britter">Convert package.html files
to package-info.java files</action>

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=1559780&r1=1559779&r2=1559780&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 Mon
Jan 20 17:19:59 2014
@@ -1689,10 +1689,10 @@ public class DateUtils {
         // Fragments bigger than a day require a breakdown to days
         switch (fragment) {
             case Calendar.YEAR:
-                result += (calendar.get(Calendar.DAY_OF_YEAR) * MILLIS_PER_DAY) / millisPerUnit;
+                result += ((calendar.get(Calendar.DAY_OF_YEAR) -1) * MILLIS_PER_DAY) / millisPerUnit;
                 break;
             case Calendar.MONTH:
-                result += (calendar.get(Calendar.DAY_OF_MONTH) * MILLIS_PER_DAY) / millisPerUnit;
+                result += ((calendar.get(Calendar.DAY_OF_MONTH) -1) * MILLIS_PER_DAY) / millisPerUnit;
                 break;
         }
 

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=1559780&r1=1559779&r2=1559780&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:19:59 2014
@@ -532,6 +532,19 @@ testResult);
     }
 
     @Test
+    public void testMinutesOfYearWithWrongOffsetBugWithCalendar() {
+        Calendar c = Calendar.getInstance();
+        c.set(Calendar.MONTH, Calendar.JANUARY);
+        c.set(Calendar.DAY_OF_YEAR, 1);
+        c.set(Calendar.HOUR_OF_DAY, 0);
+        c.set(Calendar.MINUTE, 0);
+        c.set(Calendar.SECOND, 0);
+        c.set(Calendar.MILLISECOND, 0);
+        final long testResult = DateUtils.getFragmentInMinutes(c, Calendar.YEAR);
+        assertEquals( 0, testResult);
+    }
+
+    @Test
     public void testHoursOfYearWithDate() {
         final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR);
         final Calendar cal = Calendar.getInstance();



Mime
View raw message