From dbc0831e24e391a78e490b892e958a05d7e95116 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 19 May 2011 17:18:29 -0400
Subject: [PATCH] Documentation tweak.
---
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