diff options
author | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-05-31 20:36:43 +0000 |
---|---|---|
committer | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-05-31 20:36:43 +0000 |
commit | 978650618d5b021bc1f382eb6e24207521567369 (patch) | |
tree | f006530f0f7918c50a8a9e4d1aec7b5dd06dc909 | |
parent | 26e81106b37235359167918bc74f4186510b3c05 (diff) | |
download | Essentials-978650618d5b021bc1f382eb6e24207521567369.tar Essentials-978650618d5b021bc1f382eb6e24207521567369.tar.gz Essentials-978650618d5b021bc1f382eb6e24207521567369.tar.lz Essentials-978650618d5b021bc1f382eb6e24207521567369.tar.xz Essentials-978650618d5b021bc1f382eb6e24207521567369.zip |
Fix: 1 day displayed additionally on 31th of month
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1549 e251c2fe-e539-e718-e476-b85c1f46cddb
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Util.java | 6 | ||||
-rw-r--r-- | Essentials/test/com/earth2me/essentials/UtilTest.java | 3 |
2 files changed, 7 insertions, 2 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 81447d8e9..faed72ae6 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -97,15 +97,17 @@ public class Util } private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future) - { + { int diff = 0; + long savedDate = fromDate.getTimeInMillis(); while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate))) { + savedDate = fromDate.getTimeInMillis(); fromDate.add(type, future ? 1 : -1); diff++; } diff--; - fromDate.add(type, future ? -1 : 1); + fromDate.setTimeInMillis(savedDate); return diff; } diff --git a/Essentials/test/com/earth2me/essentials/UtilTest.java b/Essentials/test/com/earth2me/essentials/UtilTest.java index 712d15cfe..4e7949448 100644 --- a/Essentials/test/com/earth2me/essentials/UtilTest.java +++ b/Essentials/test/com/earth2me/essentials/UtilTest.java @@ -93,6 +93,9 @@ public class UtilTest extends TestCase a = new GregorianCalendar(2010, 9, 17, 23, 45, 45); b = new GregorianCalendar(2015, 3, 7, 10, 0, 0); assertEquals(" 4 years 5 months 20 days 10 hours 14 minutes 15 seconds", Util.formatDateDiff(a, b)); + a = new GregorianCalendar(2011, 4, 31, 10, 0, 0); + b = new GregorianCalendar(2011, 4, 31, 10, 5, 0); + assertEquals(" 5 minutes", Util.formatDateDiff(a, b)); } public void testFDDpast() { |