Fix for ISSUE#1160 (make duration descriptions more accurate). The rules for the descriptions are as outlined in this thread: http://www.nabble.com/More-precise-time-strings-tt14781235.html

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@6879 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
dwdyer committed 2008-01-25 20:20:44 +00:00
1 parent 413c6a15fb
commit 9194bc32f0
2 files changed
+81 -21

No files matched your search

+21
View File
@@ -29,4 +29,25 @@ public class UtilTest extends TestCase {
assertEquals("a-aa", Util.replaceMacro("$A-$AA",m));
assertEquals("/a/foo/can/B/you-believe_aa~it?", Util.replaceMacro("/$A/foo/can/$B/you-believe_$AA~it?",m));
}
public void testTimeSpanString() {
// Check that amounts less than 365 days are not rounded up to a whole year.
// In the previous implementation there were 360 days in a year.
// We're still working on the assumption that a month is 30 days, so there will
// be 5 days at the end of the year that will be "12 months" but not "1 year".
// First check 359 days.
assertEquals("11 months", Util.getTimeSpanString(31017600000L));
// And 362 days.
assertEquals("12 months", Util.getTimeSpanString(31276800000L));
// 11.25 years - Check that if the first unit has 2 or more digits, a second unit isn't used.
assertEquals("11 years", Util.getTimeSpanString(354780000000L));
// 9.25 years - Check that if the first unit has only 1 digit, a second unit is used.
assertEquals("9 years 3 months", Util.getTimeSpanString(291708000000L));
// 67 seconds
assertEquals("1 minute 7 seconds", Util.getTimeSpanString(67000L));
// 17 seconds - Check that times less than a minute only use seconds.
assertEquals("17 seconds", Util.getTimeSpanString(17000L));
}
}