mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-09-12 13:19:33 +00:00
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
This commit is contained in:
parent
26e81106b3
commit
978650618d
|
@ -99,13 +99,15 @@ public class Util
|
||||||
private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future)
|
private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future)
|
||||||
{
|
{
|
||||||
int diff = 0;
|
int diff = 0;
|
||||||
|
long savedDate = fromDate.getTimeInMillis();
|
||||||
while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate)))
|
while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate)))
|
||||||
{
|
{
|
||||||
|
savedDate = fromDate.getTimeInMillis();
|
||||||
fromDate.add(type, future ? 1 : -1);
|
fromDate.add(type, future ? 1 : -1);
|
||||||
diff++;
|
diff++;
|
||||||
}
|
}
|
||||||
diff--;
|
diff--;
|
||||||
fromDate.add(type, future ? -1 : 1);
|
fromDate.setTimeInMillis(savedDate);
|
||||||
return diff;
|
return diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,9 @@ public class UtilTest extends TestCase
|
||||||
a = new GregorianCalendar(2010, 9, 17, 23, 45, 45);
|
a = new GregorianCalendar(2010, 9, 17, 23, 45, 45);
|
||||||
b = new GregorianCalendar(2015, 3, 7, 10, 0, 0);
|
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));
|
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() {
|
public void testFDDpast() {
|
||||||
|
|
Loading…
Reference in a new issue