James Moger
2012-01-05 cb285cbfddfc0b633d6b8cdb4dc0d2bd2b8b51ef
src/com/gitblit/utils/TimeUtils.java
@@ -15,10 +15,9 @@
 */
package com.gitblit.utils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import com.gitblit.models.FederationModel;
/**
 * Utility class of time functions.
@@ -55,9 +54,10 @@
    */
   public static boolean isYesterday(Date date) {
      Calendar cal = Calendar.getInstance();
      cal.setTime(date);
      cal.add(Calendar.DATE, 1);
      return (System.currentTimeMillis() - cal.getTimeInMillis()) < ONEDAY;
      cal.setTime(new Date());
      cal.add(Calendar.DATE, -1);
      SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
      return df.format(cal.getTime()).equals(df.format(date));
   }
   /**
@@ -145,15 +145,13 @@
    * Return the difference in days between now and the date.
    * 
    * @param date
    * @param roundup
    * @return days ago
    */
   public static int daysAgo(Date date, boolean roundup) {
      long diff = System.currentTimeMillis() - date.getTime();
   public static int daysAgo(Date date) {
      long today = ONEDAY * (System.currentTimeMillis()/ONEDAY);
      long day = ONEDAY * (date.getTime()/ONEDAY);
      long diff = today - day;
      int days = (int) (diff / ONEDAY);
      if (roundup && (diff % ONEDAY) > 0) {
         days++;
      }
      return days;
   }
@@ -208,7 +206,7 @@
         if (css) {
            return "age2";
         }
         int days = daysAgo(date, true);
         int days = daysAgo(date);
         if (days < 365) {
            if (days <= 30) {
               return days + " days ago";
@@ -253,11 +251,9 @@
      int mins = 60;
      if (!StringUtils.isEmpty(frequency)) {
         try {
            String str;
            String str = frequency.trim();
            if (frequency.indexOf(' ') > -1) {
               str = frequency.substring(0, frequency.indexOf(' ')).trim();
            } else {
               str = frequency.trim();
               str = str.substring(0, str.indexOf(' ')).trim();
            }
            mins = (int) Float.parseFloat(str);
         } catch (NumberFormatException e) {
@@ -268,7 +264,7 @@
      }
      if (frequency.indexOf("day") > -1) {
         // convert to minutes
         mins *= 24 * 60;
         mins *= 1440;
      } else if (frequency.indexOf("hour") > -1) {
         // convert to minutes
         mins *= 60;