diff options
author | James Moger <james.moger@gitblit.com> | 2011-04-15 17:18:51 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-04-15 17:18:51 -0400 |
commit | 87cc1ed60735a419a3ea23f20614fc0a3f9bab60 (patch) | |
tree | 272ae060613fcc4616c6ad46bc47d7048200e872 /src/com/gitblit/utils/Utils.java | |
parent | 155bf78e3377910d29b2c912f58c0f496cb428e8 (diff) | |
download | gitblit-87cc1ed60735a419a3ea23f20614fc0a3f9bab60.tar.gz gitblit-87cc1ed60735a419a3ea23f20614fc0a3f9bab60.zip |
Settings overhaul. Fixes to authentication. Bind interface feature.
Settings access has been abstracted and the way is becoming clear to
offer a WAR build in addition to the integrated server stack. Util
methods moved around.
Diffstat (limited to 'src/com/gitblit/utils/Utils.java')
-rw-r--r-- | src/com/gitblit/utils/Utils.java | 166 |
1 files changed, 0 insertions, 166 deletions
diff --git a/src/com/gitblit/utils/Utils.java b/src/com/gitblit/utils/Utils.java deleted file mode 100644 index 6d0c6b3c..00000000 --- a/src/com/gitblit/utils/Utils.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.gitblit.utils;
-
-import java.util.Date;
-
-public class Utils {
- private final static long min = 1000 * 60l;
-
- private final static long halfhour = min * 30l;
-
- private final static long onehour = halfhour * 2;
-
- private final static long oneday = onehour * 24l;
-
- @SuppressWarnings("deprecation")
- public static boolean isToday(Date date) {
- Date now = new Date();
- return now.getDate() == date.getDate() && now.getMonth() == date.getMonth() && now.getYear() == date.getYear();
- }
-
- @SuppressWarnings("deprecation")
- public static boolean isYesterday(Date date) {
- Date now = new Date();
- return now.getDate() == (date.getDate() + 1) && now.getMonth() == date.getMonth() && now.getYear() == date.getYear();
- }
-
- public static int minutesAgo(Date date, long endTime, boolean roundup) {
- long diff = endTime - date.getTime();
- int mins = (int) (diff / min);
- if (roundup && (diff % min) >= 30)
- mins++;
- return mins;
- }
-
- public static int minutesAgo(Date date, boolean roundup) {
- return minutesAgo(date, System.currentTimeMillis(), roundup);
- }
-
- public static int hoursAgo(Date date, boolean roundup) {
- long diff = System.currentTimeMillis() - date.getTime();
- int hours = (int) (diff / onehour);
- if (roundup && (diff % onehour) >= halfhour)
- hours++;
- return hours;
- }
-
- public static int daysAgo(Date date, boolean roundup) {
- long diff = System.currentTimeMillis() - date.getTime();
- int days = (int) (diff / oneday);
- if (roundup && (diff % oneday) > 0)
- days++;
- return days;
- }
-
- public static String timeAgo(Date date) {
- return timeAgo(date, false);
- }
-
- public static String timeAgoCss(Date date) {
- return timeAgo(date, true);
- }
-
- private static String timeAgo(Date date, boolean css) {
- String ago = null;
- if (isToday(date) || isYesterday(date)) {
- int mins = minutesAgo(date, true);
- if (mins > 120) {
- if (css) {
- return "age1";
- }
- int hours = hoursAgo(date, true);
- if (hours > 23) {
- ago = "yesterday";
- } else {
- ago = hours + " hour" + (hours > 1 ? "s" : "") + " ago";
- }
- } else {
- if (css) {
- return "age0";
- }
- ago = mins + " min" + (mins > 1 ? "s" : "") + " ago";
- }
- } else {
- if (css) {
- return "age2";
- }
- int days = daysAgo(date, true);
- if (days < 365) {
- if (days <= 30) {
- ago = days + " day" + (days > 1 ? "s" : "") + " ago";
- } else if (days <= 90) {
- int weeks = days / 7;
- if (weeks == 12)
- ago = "3 months ago";
- else
- ago = weeks + " weeks ago";
- } else if (days > 90) {
- int months = days / 30;
- int weeks = (days % 30) / 7;
- if (weeks >= 2)
- months++;
- ago = months + " month" + (months > 1 ? "s" : "") + " ago";
- } else
- ago = days + " day" + (days > 1 ? "s" : "") + " ago";
- } else if (days == 365) {
- ago = "1 year ago";
- } else {
- int yr = days / 365;
- days = days % 365;
- int months = (yr * 12) + (days / 30);
- if (months > 23) {
- ago = yr + " years ago";
- } else {
- ago = months + " months ago";
- }
- }
- }
- return ago;
- }
-
- public static String leftPad(String input, int length, char pad) {
- if (input.length() < length) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0, len = length - input.length(); i < len; i++) {
- sb.append(pad);
- }
- sb.append(input);
- return sb.toString();
- }
- return input;
- }
-
- public static String rightPad(String input, int length, char pad) {
- if (input.length() < length) {
- StringBuilder sb = new StringBuilder();
- sb.append(input);
- for (int i = 0, len = length - input.length(); i < len; i++) {
- sb.append(pad);
- }
- return sb.toString();
- }
- return input;
- }
-
- public static String escapeForHtml(String inStr, boolean changeSpace) {
- StringBuffer retStr = new StringBuffer();
- int i = 0;
- while (i < inStr.length()) {
- if (inStr.charAt(i) == '&') {
- retStr.append("&");
- } else if (inStr.charAt(i) == '<') {
- retStr.append("<");
- } else if (inStr.charAt(i) == '>') {
- retStr.append(">");
- } else if (inStr.charAt(i) == '\"') {
- retStr.append(""");
- } else if (changeSpace && inStr.charAt(i) == ' ') {
- retStr.append(" ");
- } else if (changeSpace && inStr.charAt(i) == '\t') {
- retStr.append(" ");
- } else
- retStr.append(inStr.charAt(i));
- i++;
- }
- return retStr.toString();
- }
-}
|