From 0e44acbb2fec928a1606dc60f427a148fff405c9 Mon Sep 17 00:00:00 2001
From: Mohamed Ragab <moragab@gmail.com>
Date: Wed, 02 May 2012 11:15:01 -0400
Subject: [PATCH] Added a script to facilitate setting the proxy host and port and no proxy hosts, and then it concatenates all the java system properties for setting the java proxy configurations and puts the resulting string in an environment variable JAVA_PROXY_CONFIG, modified the scirpts gitblit,  gitblit-ubuntu, and gitblit-centos to source the java-proxy-config.sh script and then include the resulting java proxy configuration in the java command

---
 src/com/gitblit/utils/TimeUtils.java |  103 ++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 69 insertions(+), 34 deletions(-)

diff --git a/src/com/gitblit/utils/TimeUtils.java b/src/com/gitblit/utils/TimeUtils.java
index ad81463..662025b 100644
--- a/src/com/gitblit/utils/TimeUtils.java
+++ b/src/com/gitblit/utils/TimeUtils.java
@@ -15,6 +15,7 @@
  */
 package com.gitblit.utils;
 
+import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 
@@ -53,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));
 	}
 
 	/**
@@ -143,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;
 	}
 
@@ -185,7 +185,6 @@
 	 * @return the string representation of the duration OR the css class
 	 */
 	private static String timeAgo(Date date, boolean css) {
-		String ago = null;
 		if (isToday(date) || isYesterday(date)) {
 			int mins = minutesAgo(date, true);
 			if (mins >= 120) {
@@ -194,52 +193,88 @@
 				}
 				int hours = hoursAgo(date, true);
 				if (hours > 23) {
-					ago = "yesterday";
+					return "yesterday";
 				} else {
-					ago = hours + " hours ago";
+					return hours + " hours ago";
 				}
-			} else {
-				if (css) {
-					return "age0";
-				}
-				ago = mins + " min" + (mins > 1 ? "s" : "") + " ago";
 			}
-		} else {
 			if (css) {
-				return "age2";
+				return "age0";
 			}
-			int days = daysAgo(date, true);
+			return mins + " min" + (mins > 1 ? "s" : "") + " ago";
+		} else {
+			int days = daysAgo(date);
+			if (css) {
+				if (days <= 7) {
+					return "age2";
+				} if (days <= 30) {
+					return "age3";
+				} else {
+					return "age4";
+				}
+			}
 			if (days < 365) {
 				if (days <= 30) {
-					ago = days + " days ago";
+					return days + " days ago";
 				} else if (days <= 90) {
 					int weeks = days / 7;
 					if (weeks == 12) {
-						ago = "3 months ago";
+						return "3 months ago";
 					} else {
-						ago = weeks + " weeks ago";
+						return weeks + " weeks ago";
 					}
-				} else if (days > 90) {
-					int months = days / 30;
-					int weeks = (days % 30) / 7;
-					if (weeks >= 2) {
-						months++;
-					}
-					ago = months + " months ago";
 				}
+				int months = days / 30;
+				int weeks = (days % 30) / 7;
+				if (weeks >= 2) {
+					months++;
+				}
+				return months + " months ago";
 			} else if (days == 365) {
-				ago = "1 year ago";
+				return "1 year ago";
 			} else {
 				int yr = days / 365;
 				days = days % 365;
 				int months = (yr * 12) + (days / 30);
 				if (months > 23) {
-					ago = yr + " years ago";
+					return yr + " years ago";
 				} else {
-					ago = months + " months ago";
+					return months + " months ago";
 				}
 			}
 		}
-		return ago;
+	}
+
+	/**
+	 * Convert a frequency string into minutes.
+	 * 
+	 * @param frequency
+	 * @return minutes
+	 */
+	public static int convertFrequencyToMinutes(String frequency) {
+		// parse the frequency
+		frequency = frequency.toLowerCase();
+		int mins = 60;
+		if (!StringUtils.isEmpty(frequency)) {
+			try {
+				String str = frequency.trim();
+				if (frequency.indexOf(' ') > -1) {
+					str = str.substring(0, str.indexOf(' ')).trim();
+				}
+				mins = (int) Float.parseFloat(str);
+			} catch (NumberFormatException e) {
+			}
+			if (mins < 5) {
+				mins = 5;
+			}
+		}
+		if (frequency.indexOf("day") > -1) {
+			// convert to minutes
+			mins *= 1440;
+		} else if (frequency.indexOf("hour") > -1) {
+			// convert to minutes
+			mins *= 60;
+		}
+		return mins;
 	}
 }

--
Gitblit v1.9.1