From c7ebb2407112b8137e2cd7c108dd13957b4cff1e Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 28 Sep 2011 20:44:23 -0400
Subject: [PATCH] Allow SSL renegotiation on Java 1.6.0_22 and later
---
src/com/gitblit/utils/TimeUtils.java | 79 ++++++++++++++++++++++++++++-----------
1 files changed, 57 insertions(+), 22 deletions(-)
diff --git a/src/com/gitblit/utils/TimeUtils.java b/src/com/gitblit/utils/TimeUtils.java
index ad81463..056735c 100644
--- a/src/com/gitblit/utils/TimeUtils.java
+++ b/src/com/gitblit/utils/TimeUtils.java
@@ -18,6 +18,8 @@
import java.util.Calendar;
import java.util.Date;
+import com.gitblit.models.FederationModel;
+
/**
* Utility class of time functions.
*
@@ -185,7 +187,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,16 +195,15 @@
}
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";
}
+ if (css) {
+ return "age0";
+ }
+ return mins + " min" + (mins > 1 ? "s" : "") + " ago";
} else {
if (css) {
return "age2";
@@ -211,35 +211,70 @@
int days = daysAgo(date, true);
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;
+ if (frequency.indexOf(' ') > -1) {
+ str = frequency.substring(0, frequency.indexOf(' ')).trim();
+ } else {
+ str = frequency.trim();
+ }
+ mins = (int) Float.parseFloat(str);
+ } catch (NumberFormatException e) {
+ }
+ if (mins < 5) {
+ mins = 5;
+ }
+ }
+ if (frequency.indexOf("day") > -1) {
+ // convert to minutes
+ mins *= 24 * 60;
+ } else if (frequency.indexOf("hour") > -1) {
+ // convert to minutes
+ mins *= 60;
+ } else if (frequency.indexOf("min") > -1) {
+ // default mins
+ }
+ return mins;
}
}
--
Gitblit v1.9.1