From 790c3829edafcb41d6eeb14301a23db22c559e96 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Fri, 01 Jul 2011 17:45:23 -0400 Subject: [PATCH] Documentation. Added upgrade info to site. Moved todos to GoogleCode. --- src/com/gitblit/utils/TimeUtils.java | 46 ++++++++++++++++++---------------------------- 1 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/com/gitblit/utils/TimeUtils.java b/src/com/gitblit/utils/TimeUtils.java index 16aea77..dcb60ab 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.util.Calendar; import java.util.Date; public class TimeUtils { @@ -28,26 +29,23 @@ public static final long ONEYEAR = ONEDAY * 365L; - @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(); + return (System.currentTimeMillis() - date.getTime()) < ONEDAY; } - @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(); + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.add(Calendar.DATE, 1); + return (System.currentTimeMillis() - cal.getTimeInMillis()) < ONEDAY; } public static String duration(int days) { if (days <= 60) { return days + (days > 1 ? " days" : " day"); - } else if (days <= 365) { + } else if (days < 365) { int rem = days % 30; - return (days / 30) + " months, " + rem + (rem > 1 ? " days" : " day"); + return ((days / 30) + (rem >= 15 ? 1 : 0)) + " months"; } else { int years = days / 365; int rem = days % 365; @@ -56,23 +54,17 @@ if (rem == 0) { return yearsString; } else { - return yearsString + ", " + rem + (rem > 1 ? " days" : " day"); + return yearsString + (rem >= 15 ? ", 1 month" : ""); } } 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 >= 15) { + months++; } - if (remDays == 0) { - return monthsString; - } else { - return monthsString + ", " + remDays + (remDays > 1 ? " days" : " day"); - } + String monthsString = yearsString + ", " + months + + (months > 1 ? " months" : " month"); + return monthsString; } } } @@ -120,7 +112,7 @@ String ago = null; if (isToday(date) || isYesterday(date)) { int mins = minutesAgo(date, true); - if (mins > 120) { + if (mins >= 120) { if (css) { return "age1"; } @@ -128,7 +120,7 @@ if (hours > 23) { ago = "yesterday"; } else { - ago = hours + " hour" + (hours > 1 ? "s" : "") + " ago"; + ago = hours + " hours ago"; } } else { if (css) { @@ -143,7 +135,7 @@ int days = daysAgo(date, true); if (days < 365) { if (days <= 30) { - ago = days + " day" + (days > 1 ? "s" : "") + " ago"; + ago = days + " days ago"; } else if (days <= 90) { int weeks = days / 7; if (weeks == 12) { @@ -157,9 +149,7 @@ if (weeks >= 2) { months++; } - ago = months + " month" + (months > 1 ? "s" : "") + " ago"; - } else { - ago = days + " day" + (days > 1 ? "s" : "") + " ago"; + ago = months + " months ago"; } } else if (days == 365) { ago = "1 year ago"; -- Gitblit v1.9.1