From 166e6a131d0693d20b3cc08f252705608d24d5f0 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Wed, 27 Apr 2011 21:56:56 -0400 Subject: [PATCH] Improve repo folder detection. Fail gracefully on create repo error. --- src/com/gitblit/utils/TimeUtils.java | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) diff --git a/src/com/gitblit/utils/TimeUtils.java b/src/com/gitblit/utils/TimeUtils.java index 60b525b..c4e5b59 100644 --- a/src/com/gitblit/utils/TimeUtils.java +++ b/src/com/gitblit/utils/TimeUtils.java @@ -23,6 +23,40 @@ return now.getDate() == (date.getDate() + 1) && now.getMonth() == date.getMonth() && now.getYear() == date.getYear(); } + public static String duration(int days) { + if (days <= 60) { + return days + (days > 1 ? " days" : " day"); + } else if (days <= 365) { + int rem = days % 30; + return (days / 30) + " months, " + rem + (rem > 1 ? " days" : " day"); + } else { + int years = days / 365; + int rem = days % 365; + String yearsString = years + (years > 1 ? " years" : " year"); + if (rem < 30) { + if (rem == 0) { + return yearsString; + } else { + return yearsString + ", " + rem + (rem > 1 ? " days" : " day"); + } + } else { + int months = rem / 30; + int remDays = (rem % 30); + String monthsString; + if (months == 0) { + monthsString = yearsString; + } else { + monthsString = yearsString + ", " + months + (months > 1 ? " months" : " month"); + } + if (remDays == 0) { + return monthsString; + } else { + return monthsString + ", " + remDays + (remDays > 1 ? " days":" day"); + } + } + } + } + public static int minutesAgo(Date date, long endTime, boolean roundup) { long diff = endTime - date.getTime(); int mins = (int) (diff / min); -- Gitblit v1.9.1