]> source.dussan.org Git - gitblit.git/commitdiff
TimeUtils: Move unit test to same package as TimeUtils is
authorFlorian Zschocke <f.zschocke+git@gmail.com>
Sat, 23 Oct 2021 21:41:25 +0000 (23:41 +0200)
committerFlorian Zschocke <f.zschocke+git@gmail.com>
Sat, 23 Oct 2021 21:47:47 +0000 (23:47 +0200)
For some reason the `TimeUtilsTest` class is, like almost all tests, in
the `com.gitblit.tests` package. But this way all methods in classes
which we might predominately need for tests have to be public.
So move the unit test class `TimeUtilsTest` to the same package as the
class it is testing, i.e. `com.gitblit.utils.TimeUtils`.
This way we ca set the new added methods which get the current time
passed in to be at least not public.

src/main/java/com/gitblit/utils/TimeUtils.java
src/test/java/com/gitblit/tests/GitBlitSuite.java
src/test/java/com/gitblit/tests/TimeUtilsTest.java [deleted file]
src/test/java/com/gitblit/utils/TimeUtilsTest.java [new file with mode: 0644]

index 001e6be6afe6b90f9745f935e66663ef2fda4402..1273704706e02d5592bd4a2b72af8ab76df1e66d 100644 (file)
@@ -63,7 +63,7 @@ public class TimeUtils {
        }\r
 \r
 \r
-       public static boolean isToday(Date date, TimeZone timezone, Date now) {\r
+       static boolean isToday(Date date, TimeZone timezone, Date now) {\r
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");\r
                if (timezone != null) {\r
                        df.setTimeZone(timezone);\r
@@ -82,7 +82,7 @@ public class TimeUtils {
        }\r
 \r
 \r
-       public static boolean isYesterday(Date date, TimeZone timezone, Date now) {\r
+       static boolean isYesterday(Date date, TimeZone timezone, Date now) {\r
                Calendar cal = Calendar.getInstance();\r
                cal.setTime(now);\r
                cal.add(Calendar.DATE, -1);\r
@@ -170,7 +170,7 @@ public class TimeUtils {
        }\r
 \r
 \r
-       public static int hoursAgo(Date date, long now, boolean roundup) {\r
+       static int hoursAgo(Date date, long now, boolean roundup) {\r
                long diff = now - date.getTime();\r
                int hours = (int) (diff / ONEHOUR);\r
                if (roundup && (diff % ONEHOUR) >= HALFHOUR) {\r
@@ -189,7 +189,7 @@ public class TimeUtils {
                return daysAgo(date, System.currentTimeMillis());\r
        }\r
 \r
-       public static int daysAgo(Date date, long now) {\r
+       static int daysAgo(Date date, long now) {\r
                long today = ONEDAY * (now/ONEDAY);\r
                long day = ONEDAY * (date.getTime()/ONEDAY);\r
                long diff = today - day;\r
@@ -239,7 +239,7 @@ public class TimeUtils {
        }\r
 \r
 \r
-       public String timeAgo(Date date, boolean css, long now) {\r
+       String timeAgo(Date date, boolean css, long now) {\r
                Date dNow = new Date(now);\r
                if (isToday(date, timezone, dNow) || isYesterday(date, timezone, dNow)) {\r
                        int mins = minutesAgo(date, now, true);\r
index 3292d09089e248105b3247ea7eb9415748933cb9..fbae039ce355b275843bcb7defe2285e2721fd24 100644 (file)
@@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import java.util.zip.ZipEntry;\r
 import java.util.zip.ZipInputStream;\r
 \r
+import com.gitblit.utils.TimeUtilsTest;\r
 import org.eclipse.jgit.api.Git;\r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.lib.RepositoryCache;\r
diff --git a/src/test/java/com/gitblit/tests/TimeUtilsTest.java b/src/test/java/com/gitblit/tests/TimeUtilsTest.java
deleted file mode 100644 (file)
index 2dde6d5..0000000
+++ /dev/null
@@ -1,265 +0,0 @@
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.tests;\r
-\r
-import java.util.Calendar;\r
-import java.util.Date;\r
-import java.util.TimeZone;\r
-\r
-import org.junit.Test;\r
-\r
-import com.gitblit.utils.TimeUtils;\r
-\r
-public class TimeUtilsTest extends GitblitUnitTest {\r
-\r
-       private Date offset(long subtract) {\r
-               return new Date(System.currentTimeMillis() - subtract);\r
-       }\r
-\r
-       private Date offset(long now, long subtract) {\r
-               return new Date(now - subtract);\r
-       }\r
-\r
-       @Test\r
-       public void testBasicTimeFunctions() throws Exception {\r
-               assertEquals(2, TimeUtils.minutesAgo(offset(2 * TimeUtils.MIN), false));\r
-               assertEquals(3, TimeUtils.minutesAgo(offset((2 * TimeUtils.MIN) + (35 * 1000L)), true));\r
-\r
-               assertEquals(2, TimeUtils.hoursAgo(offset(2 * TimeUtils.ONEHOUR), false));\r
-               assertEquals(3, TimeUtils.hoursAgo(offset(5 * TimeUtils.HALFHOUR), true));\r
-\r
-               assertEquals(4, TimeUtils.daysAgo(offset(4 * TimeUtils.ONEDAY)));\r
-       }\r
-\r
-       @Test\r
-       public void testToday() throws Exception {\r
-               assertTrue(TimeUtils.isToday(new Date(), null));\r
-       }\r
-\r
-       @Test\r
-       public void testYesterday() throws Exception {\r
-               assertTrue(TimeUtils.isYesterday(offset(TimeUtils.ONEDAY), null));\r
-       }\r
-\r
-       @Test\r
-       public void testDurations() throws Exception {\r
-               TimeUtils timeUtils = new TimeUtils();\r
-               assertEquals("1 day", timeUtils.duration(1));\r
-               assertEquals("5 days", timeUtils.duration(5));\r
-               assertEquals("3 months", timeUtils.duration(75));\r
-               assertEquals("12 months", timeUtils.duration(364));\r
-               assertEquals("1 year", timeUtils.duration(365 + 0));\r
-               assertEquals("1 year", timeUtils.duration(365 + 10));\r
-               assertEquals("1 year, 1 month", timeUtils.duration(365 + 15));\r
-               assertEquals("1 year, 1 month", timeUtils.duration(365 + 30));\r
-               assertEquals("1 year, 1 month", timeUtils.duration(365 + 44));\r
-               assertEquals("1 year, 2 months", timeUtils.duration(365 + 45));\r
-               assertEquals("1 year, 2 months", timeUtils.duration(365 + 60));\r
-\r
-               assertEquals("2 years", timeUtils.duration(2 * 365 + 0));\r
-               assertEquals("2 years", timeUtils.duration(2 * 365 + 10));\r
-               assertEquals("2 years, 1 month", timeUtils.duration(2 * 365 + 15));\r
-               assertEquals("2 years, 1 month", timeUtils.duration(2 * 365 + 30));\r
-               assertEquals("2 years, 1 month", timeUtils.duration(2 * 365 + 44));\r
-               assertEquals("2 years, 2 months", timeUtils.duration(2 * 365 + 45));\r
-               assertEquals("2 years, 2 months", timeUtils.duration(2 * 365 + 60));\r
-       }\r
-\r
-       @Test\r
-       public void testTimeAgo() throws Exception {\r
-               // standard time ago tests\r
-               TimeUtils timeUtils = new TimeUtils();\r
-               assertEquals("just now", timeUtils.timeAgo(offset(1 * TimeUtils.MIN)));\r
-               assertEquals("60 mins ago", timeUtils.timeAgo(offset(60 * TimeUtils.MIN)));\r
-               assertEquals("2 hours ago", timeUtils.timeAgo(offset(120 * TimeUtils.MIN)));\r
-               assertEquals("15 hours ago", timeUtils.timeAgo(offset(15 * TimeUtils.ONEHOUR)));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(24 * TimeUtils.ONEHOUR)));\r
-               assertEquals("2 days ago", timeUtils.timeAgo(offset(2 * TimeUtils.ONEDAY)));\r
-               assertEquals("5 weeks ago", timeUtils.timeAgo(offset(35 * TimeUtils.ONEDAY)));\r
-               assertEquals("3 months ago", timeUtils.timeAgo(offset(84 * TimeUtils.ONEDAY)));\r
-               assertEquals("3 months ago", timeUtils.timeAgo(offset(95 * TimeUtils.ONEDAY)));\r
-               assertEquals("4 months ago", timeUtils.timeAgo(offset(104 * TimeUtils.ONEDAY)));\r
-               assertEquals("1 year ago", timeUtils.timeAgo(offset(365 * TimeUtils.ONEDAY)));\r
-               assertEquals("13 months ago", timeUtils.timeAgo(offset(395 * TimeUtils.ONEDAY)));\r
-               assertEquals("2 years ago", timeUtils.timeAgo(offset((2 * 365 + 30) * TimeUtils.ONEDAY)));\r
-       }\r
-\r
-       @Test\r
-       public void testTimeAgoCss() throws Exception {\r
-               // css class tests\r
-               TimeUtils timeUtils = new TimeUtils();\r
-               assertEquals("age0", timeUtils.timeAgoCss(offset(1 * TimeUtils.MIN)));\r
-               assertEquals("age0", timeUtils.timeAgoCss(offset(60 * TimeUtils.MIN)));\r
-               assertEquals("age1", timeUtils.timeAgoCss(offset(120 * TimeUtils.MIN)));\r
-               assertEquals("age1", timeUtils.timeAgoCss(offset(24 * TimeUtils.ONEHOUR)));\r
-               assertEquals("age2", timeUtils.timeAgoCss(offset(2 * TimeUtils.ONEDAY)));\r
-       }\r
-\r
-\r
-       @Test\r
-       public void testTimeAgoYesterday() throws Exception {\r
-               TimeZone myTimezone = TimeZone.getTimeZone("GMT");\r
-               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
-\r
-               Calendar myCal = Calendar.getInstance(myTimezone);\r
-               myCal.set(Calendar.HOUR_OF_DAY, 12);\r
-               myCal.set(Calendar.MINUTE, 0);\r
-               long now = myCal.getTime().getTime();\r
-\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,23 * TimeUtils.ONEHOUR), false, now));\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (29 * TimeUtils.MIN)), false, now));\r
-\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (31 * TimeUtils.MIN)), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,35 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,36 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,37 * TimeUtils.ONEHOUR), false, now));\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,44 * TimeUtils.ONEHOUR), false, now));\r
-       }\r
-\r
-       @Test\r
-       public void testTimeAgoYesterdayCET() throws Exception {\r
-               TimeZone myTimezone = TimeZone.getTimeZone("CET");\r
-               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
-\r
-               Calendar myCal = Calendar.getInstance(myTimezone);\r
-               myCal.set(Calendar.HOUR_OF_DAY, 22);\r
-               myCal.set(Calendar.MINUTE, 0);\r
-               long now = myCal.getTime().getTime();\r
-\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,23 * TimeUtils.ONEHOUR), false, now));\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (29 * TimeUtils.MIN)), false, now));\r
-\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (31 * TimeUtils.MIN)), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,36 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,46 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,47 * TimeUtils.ONEHOUR), false, now));\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,56 * TimeUtils.ONEHOUR), false, now));\r
-       }\r
-\r
-\r
-       @Test\r
-       public void testTimeAgoYesterdayPST() throws Exception {\r
-               TimeZone myTimezone = TimeZone.getTimeZone("PST");\r
-               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
-\r
-               Calendar myCal = Calendar.getInstance(myTimezone);\r
-               myCal.set(Calendar.HOUR_OF_DAY, 8);\r
-               myCal.set(Calendar.MINUTE, 0);\r
-               long now = myCal.getTime().getTime();\r
-\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,23 * TimeUtils.ONEHOUR), false, now));\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (29 * TimeUtils.MIN)), false, now));\r
-\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (31 * TimeUtils.MIN)), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,30 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,32 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,33 * TimeUtils.ONEHOUR), false, now));\r
-               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,48 * TimeUtils.ONEHOUR), false, now));\r
-       }\r
-\r
-       @Test\r
-       public void testFrequency() {\r
-               assertEquals(5, TimeUtils.convertFrequencyToMinutes("2 mins", 5));\r
-               assertEquals(10, TimeUtils.convertFrequencyToMinutes("10 mins", 5));\r
-               assertEquals(600, TimeUtils.convertFrequencyToMinutes("10 hours", 5));\r
-               assertEquals(14400, TimeUtils.convertFrequencyToMinutes(" 10 days ", 5));\r
-       }\r
-\r
-\r
-       @Test\r
-       public void testTimeAgoDaysAgo() throws Exception {\r
-               TimeZone myTimezone = TimeZone.getTimeZone("GMT");\r
-               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
-\r
-               Calendar myCal = Calendar.getInstance(myTimezone);\r
-               myCal.set(Calendar.HOUR_OF_DAY, 12);\r
-               myCal.set(Calendar.MINUTE, 0);\r
-               long now = myCal.getTime().getTime();\r
-\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,36 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,37 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,48 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,60 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,61 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,72 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,84 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertEquals("4 days ago", timeUtils.timeAgo(offset(now,85 * TimeUtils.ONEHOUR), false, now));\r
-       }\r
-\r
-\r
-\r
-       @Test\r
-       public void testTimeAgoDaysAgoCET() throws Exception {\r
-               TimeZone myTimezone = TimeZone.getTimeZone("CET");\r
-               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
-\r
-               Calendar myCal = Calendar.getInstance(myTimezone);\r
-               myCal.set(Calendar.HOUR_OF_DAY, 8);\r
-               myCal.set(Calendar.MINUTE, 0);\r
-               long now = myCal.getTime().getTime();\r
-\r
-\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,32 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,33 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,48 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,56 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,57 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,72 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,80 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertEquals("4 days ago", timeUtils.timeAgo(offset(now,81 * TimeUtils.ONEHOUR), false, now));\r
-       }\r
-\r
-\r
-\r
-       @Test\r
-       public void testTimeAgoDaysAgoPST() throws Exception {\r
-               TimeZone myTimezone = TimeZone.getTimeZone("PST");\r
-               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
-\r
-               Calendar myCal = Calendar.getInstance(myTimezone);\r
-               myCal.set(Calendar.HOUR_OF_DAY, 22);\r
-               myCal.set(Calendar.MINUTE, 0);\r
-               long now = myCal.getTime().getTime();\r
-\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("yesterday", timeUtils.timeAgo(offset(now,46 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,47 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,48 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,70 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,71 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,72 * TimeUtils.ONEHOUR), false, now));\r
-               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,94 * TimeUtils.ONEHOUR), false, now));\r
-\r
-               assertEquals("4 days ago", timeUtils.timeAgo(offset(now,95 * TimeUtils.ONEHOUR), false, now));\r
-       }\r
-\r
-}\r
diff --git a/src/test/java/com/gitblit/utils/TimeUtilsTest.java b/src/test/java/com/gitblit/utils/TimeUtilsTest.java
new file mode 100644 (file)
index 0000000..77710e0
--- /dev/null
@@ -0,0 +1,266 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.utils;\r
+\r
+import java.util.Calendar;\r
+import java.util.Date;\r
+import java.util.TimeZone;\r
+\r
+import com.gitblit.tests.GitblitUnitTest;\r
+import org.junit.Test;\r
+\r
+\r
+public class TimeUtilsTest extends GitblitUnitTest\r
+{\r
+\r
+       private Date offset(long subtract) {\r
+               return new Date(System.currentTimeMillis() - subtract);\r
+       }\r
+\r
+       private Date offset(long now, long subtract) {\r
+               return new Date(now - subtract);\r
+       }\r
+\r
+       @Test\r
+       public void testBasicTimeFunctions() throws Exception {\r
+               assertEquals(2, TimeUtils.minutesAgo(offset(2 * TimeUtils.MIN), false));\r
+               assertEquals(3, TimeUtils.minutesAgo(offset((2 * TimeUtils.MIN) + (35 * 1000L)), true));\r
+\r
+               assertEquals(2, TimeUtils.hoursAgo(offset(2 * TimeUtils.ONEHOUR), false));\r
+               assertEquals(3, TimeUtils.hoursAgo(offset(5 * TimeUtils.HALFHOUR), true));\r
+\r
+               assertEquals(4, TimeUtils.daysAgo(offset(4 * TimeUtils.ONEDAY)));\r
+       }\r
+\r
+       @Test\r
+       public void testToday() throws Exception {\r
+               assertTrue(TimeUtils.isToday(new Date(), null));\r
+       }\r
+\r
+       @Test\r
+       public void testYesterday() throws Exception {\r
+               assertTrue(TimeUtils.isYesterday(offset(TimeUtils.ONEDAY), null));\r
+       }\r
+\r
+       @Test\r
+       public void testDurations() throws Exception {\r
+               TimeUtils timeUtils = new TimeUtils();\r
+               assertEquals("1 day", timeUtils.duration(1));\r
+               assertEquals("5 days", timeUtils.duration(5));\r
+               assertEquals("3 months", timeUtils.duration(75));\r
+               assertEquals("12 months", timeUtils.duration(364));\r
+               assertEquals("1 year", timeUtils.duration(365 + 0));\r
+               assertEquals("1 year", timeUtils.duration(365 + 10));\r
+               assertEquals("1 year, 1 month", timeUtils.duration(365 + 15));\r
+               assertEquals("1 year, 1 month", timeUtils.duration(365 + 30));\r
+               assertEquals("1 year, 1 month", timeUtils.duration(365 + 44));\r
+               assertEquals("1 year, 2 months", timeUtils.duration(365 + 45));\r
+               assertEquals("1 year, 2 months", timeUtils.duration(365 + 60));\r
+\r
+               assertEquals("2 years", timeUtils.duration(2 * 365 + 0));\r
+               assertEquals("2 years", timeUtils.duration(2 * 365 + 10));\r
+               assertEquals("2 years, 1 month", timeUtils.duration(2 * 365 + 15));\r
+               assertEquals("2 years, 1 month", timeUtils.duration(2 * 365 + 30));\r
+               assertEquals("2 years, 1 month", timeUtils.duration(2 * 365 + 44));\r
+               assertEquals("2 years, 2 months", timeUtils.duration(2 * 365 + 45));\r
+               assertEquals("2 years, 2 months", timeUtils.duration(2 * 365 + 60));\r
+       }\r
+\r
+       @Test\r
+       public void testTimeAgo() throws Exception {\r
+               // standard time ago tests\r
+               TimeUtils timeUtils = new TimeUtils();\r
+               assertEquals("just now", timeUtils.timeAgo(offset(1 * TimeUtils.MIN)));\r
+               assertEquals("60 mins ago", timeUtils.timeAgo(offset(60 * TimeUtils.MIN)));\r
+               assertEquals("2 hours ago", timeUtils.timeAgo(offset(120 * TimeUtils.MIN)));\r
+               assertEquals("15 hours ago", timeUtils.timeAgo(offset(15 * TimeUtils.ONEHOUR)));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(24 * TimeUtils.ONEHOUR)));\r
+               assertEquals("2 days ago", timeUtils.timeAgo(offset(2 * TimeUtils.ONEDAY)));\r
+               assertEquals("5 weeks ago", timeUtils.timeAgo(offset(35 * TimeUtils.ONEDAY)));\r
+               assertEquals("3 months ago", timeUtils.timeAgo(offset(84 * TimeUtils.ONEDAY)));\r
+               assertEquals("3 months ago", timeUtils.timeAgo(offset(95 * TimeUtils.ONEDAY)));\r
+               assertEquals("4 months ago", timeUtils.timeAgo(offset(104 * TimeUtils.ONEDAY)));\r
+               assertEquals("1 year ago", timeUtils.timeAgo(offset(365 * TimeUtils.ONEDAY)));\r
+               assertEquals("13 months ago", timeUtils.timeAgo(offset(395 * TimeUtils.ONEDAY)));\r
+               assertEquals("2 years ago", timeUtils.timeAgo(offset((2 * 365 + 30) * TimeUtils.ONEDAY)));\r
+       }\r
+\r
+       @Test\r
+       public void testTimeAgoCss() throws Exception {\r
+               // css class tests\r
+               TimeUtils timeUtils = new TimeUtils();\r
+               assertEquals("age0", timeUtils.timeAgoCss(offset(1 * TimeUtils.MIN)));\r
+               assertEquals("age0", timeUtils.timeAgoCss(offset(60 * TimeUtils.MIN)));\r
+               assertEquals("age1", timeUtils.timeAgoCss(offset(120 * TimeUtils.MIN)));\r
+               assertEquals("age1", timeUtils.timeAgoCss(offset(24 * TimeUtils.ONEHOUR)));\r
+               assertEquals("age2", timeUtils.timeAgoCss(offset(2 * TimeUtils.ONEDAY)));\r
+       }\r
+\r
+\r
+       @Test\r
+       public void testTimeAgoYesterday() throws Exception {\r
+               TimeZone myTimezone = TimeZone.getTimeZone("GMT");\r
+               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
+\r
+               Calendar myCal = Calendar.getInstance(myTimezone);\r
+               myCal.set(Calendar.HOUR_OF_DAY, 12);\r
+               myCal.set(Calendar.MINUTE, 0);\r
+               long now = myCal.getTime().getTime();\r
+\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,23 * TimeUtils.ONEHOUR), false, now));\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (29 * TimeUtils.MIN)), false, now));\r
+\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (31 * TimeUtils.MIN)), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,35 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,36 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,37 * TimeUtils.ONEHOUR), false, now));\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,44 * TimeUtils.ONEHOUR), false, now));\r
+       }\r
+\r
+       @Test\r
+       public void testTimeAgoYesterdayCET() throws Exception {\r
+               TimeZone myTimezone = TimeZone.getTimeZone("CET");\r
+               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
+\r
+               Calendar myCal = Calendar.getInstance(myTimezone);\r
+               myCal.set(Calendar.HOUR_OF_DAY, 22);\r
+               myCal.set(Calendar.MINUTE, 0);\r
+               long now = myCal.getTime().getTime();\r
+\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,23 * TimeUtils.ONEHOUR), false, now));\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (29 * TimeUtils.MIN)), false, now));\r
+\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (31 * TimeUtils.MIN)), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,36 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,46 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,47 * TimeUtils.ONEHOUR), false, now));\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,56 * TimeUtils.ONEHOUR), false, now));\r
+       }\r
+\r
+\r
+       @Test\r
+       public void testTimeAgoYesterdayPST() throws Exception {\r
+               TimeZone myTimezone = TimeZone.getTimeZone("PST");\r
+               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
+\r
+               Calendar myCal = Calendar.getInstance(myTimezone);\r
+               myCal.set(Calendar.HOUR_OF_DAY, 8);\r
+               myCal.set(Calendar.MINUTE, 0);\r
+               long now = myCal.getTime().getTime();\r
+\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,23 * TimeUtils.ONEHOUR), false, now));\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (29 * TimeUtils.MIN)), false, now));\r
+\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,(23 * TimeUtils.ONEHOUR) + (31 * TimeUtils.MIN)), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,30 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,32 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,33 * TimeUtils.ONEHOUR), false, now));\r
+               assertNotEquals("yesterday", timeUtils.timeAgo(offset(now,48 * TimeUtils.ONEHOUR), false, now));\r
+       }\r
+\r
+       @Test\r
+       public void testFrequency() {\r
+               assertEquals(5, TimeUtils.convertFrequencyToMinutes("2 mins", 5));\r
+               assertEquals(10, TimeUtils.convertFrequencyToMinutes("10 mins", 5));\r
+               assertEquals(600, TimeUtils.convertFrequencyToMinutes("10 hours", 5));\r
+               assertEquals(14400, TimeUtils.convertFrequencyToMinutes(" 10 days ", 5));\r
+       }\r
+\r
+\r
+       @Test\r
+       public void testTimeAgoDaysAgo() throws Exception {\r
+               TimeZone myTimezone = TimeZone.getTimeZone("GMT");\r
+               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
+\r
+               Calendar myCal = Calendar.getInstance(myTimezone);\r
+               myCal.set(Calendar.HOUR_OF_DAY, 12);\r
+               myCal.set(Calendar.MINUTE, 0);\r
+               long now = myCal.getTime().getTime();\r
+\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,36 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,37 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,48 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,60 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,61 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,72 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,84 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertEquals("4 days ago", timeUtils.timeAgo(offset(now,85 * TimeUtils.ONEHOUR), false, now));\r
+       }\r
+\r
+\r
+\r
+       @Test\r
+       public void testTimeAgoDaysAgoCET() throws Exception {\r
+               TimeZone myTimezone = TimeZone.getTimeZone("CET");\r
+               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
+\r
+               Calendar myCal = Calendar.getInstance(myTimezone);\r
+               myCal.set(Calendar.HOUR_OF_DAY, 8);\r
+               myCal.set(Calendar.MINUTE, 0);\r
+               long now = myCal.getTime().getTime();\r
+\r
+\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,32 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,33 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,48 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,56 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,57 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,72 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,80 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertEquals("4 days ago", timeUtils.timeAgo(offset(now,81 * TimeUtils.ONEHOUR), false, now));\r
+       }\r
+\r
+\r
+\r
+       @Test\r
+       public void testTimeAgoDaysAgoPST() throws Exception {\r
+               TimeZone myTimezone = TimeZone.getTimeZone("PST");\r
+               TimeUtils timeUtils = new TimeUtils(null, myTimezone);\r
+\r
+               Calendar myCal = Calendar.getInstance(myTimezone);\r
+               myCal.set(Calendar.HOUR_OF_DAY, 22);\r
+               myCal.set(Calendar.MINUTE, 0);\r
+               long now = myCal.getTime().getTime();\r
+\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,24 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("yesterday", timeUtils.timeAgo(offset(now,46 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,47 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,48 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("2 days ago", timeUtils.timeAgo(offset(now,70 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,71 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,72 * TimeUtils.ONEHOUR), false, now));\r
+               assertEquals("3 days ago", timeUtils.timeAgo(offset(now,94 * TimeUtils.ONEHOUR), false, now));\r
+\r
+               assertEquals("4 days ago", timeUtils.timeAgo(offset(now,95 * TimeUtils.ONEHOUR), false, now));\r
+       }\r
+\r
+}\r