From 3f5b8f5d9203aa7ffb7fbe9cdbaf9dba3da6cae6 Mon Sep 17 00:00:00 2001
From: Hybris95 <hybris_95@hotmail.com>
Date: Thu, 01 May 2014 16:14:15 -0400
Subject: [PATCH] Fixes sort, page building and search functions on "my tickets" page.

---
 src/main/java/com/gitblit/utils/TimeUtils.java |   62 ++++++++++++++++++------------
 1 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/src/main/java/com/gitblit/utils/TimeUtils.java b/src/main/java/com/gitblit/utils/TimeUtils.java
index ec8871c..4b113be 100644
--- a/src/main/java/com/gitblit/utils/TimeUtils.java
+++ b/src/main/java/com/gitblit/utils/TimeUtils.java
@@ -20,12 +20,13 @@
 import java.util.Calendar;
 import java.util.Date;
 import java.util.ResourceBundle;
+import java.util.TimeZone;
 
 /**
  * Utility class of time functions.
- * 
+ *
  * @author James Moger
- * 
+ *
  */
 public class TimeUtils {
 	public static final long MIN = 1000 * 60L;
@@ -37,45 +38,56 @@
 	public static final long ONEDAY = ONEHOUR * 24L;
 
 	public static final long ONEYEAR = ONEDAY * 365L;
-	
+
 	private final ResourceBundle translation;
-	
+
+	private final TimeZone timezone;
+
 	public TimeUtils() {
-		this(null);
+		this(null, null);
 	}
-	
-	public TimeUtils(ResourceBundle translation) {
+
+	public TimeUtils(ResourceBundle translation, TimeZone timezone) {
 		this.translation = translation;
+		this.timezone = timezone;
 	}
 
 	/**
 	 * Returns true if date is today.
-	 * 
+	 *
 	 * @param date
 	 * @return true if date is today
 	 */
-	public static boolean isToday(Date date) {
-		return (System.currentTimeMillis() - date.getTime()) < ONEDAY;
+	public static boolean isToday(Date date, TimeZone timezone) {
+		Date now = new Date();
+		SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
+		if (timezone != null) {
+			df.setTimeZone(timezone);
+		}
+		return df.format(now).equals(df.format(date));
 	}
 
 	/**
 	 * Returns true if date is yesterday.
-	 * 
+	 *
 	 * @param date
 	 * @return true if date is yesterday
 	 */
-	public static boolean isYesterday(Date date) {
+	public static boolean isYesterday(Date date, TimeZone timezone) {
 		Calendar cal = Calendar.getInstance();
 		cal.setTime(new Date());
 		cal.add(Calendar.DATE, -1);
 		SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
+		if (timezone != null) {
+			df.setTimeZone(timezone);
+		}
 		return df.format(cal.getTime()).equals(df.format(date));
 	}
 
 	/**
 	 * Returns the string representation of the duration as days, months and/or
 	 * years.
-	 * 
+	 *
 	 * @param days
 	 * @return duration as string in days, months, and/or years
 	 */
@@ -111,7 +123,7 @@
 	/**
 	 * Returns the number of minutes ago between the start time and the end
 	 * time.
-	 * 
+	 *
 	 * @param date
 	 * @param endTime
 	 * @param roundup
@@ -128,7 +140,7 @@
 
 	/**
 	 * Return the difference in minutes between now and the date.
-	 * 
+	 *
 	 * @param date
 	 * @param roundup
 	 * @return minutes ago
@@ -139,7 +151,7 @@
 
 	/**
 	 * Return the difference in hours between now and the date.
-	 * 
+	 *
 	 * @param date
 	 * @param roundup
 	 * @return hours ago
@@ -155,7 +167,7 @@
 
 	/**
 	 * Return the difference in days between now and the date.
-	 * 
+	 *
 	 * @param date
 	 * @return days ago
 	 */
@@ -178,7 +190,7 @@
 	/**
 	 * Returns the string representation of the duration between now and the
 	 * date.
-	 * 
+	 *
 	 * @param date
 	 * @return duration as a string
 	 */
@@ -188,7 +200,7 @@
 
 	/**
 	 * Returns the CSS class for the date based on its age from Now.
-	 * 
+	 *
 	 * @param date
 	 * @return the css class
 	 */
@@ -199,13 +211,13 @@
 	/**
 	 * Returns the string representation of the duration OR the css class for
 	 * the duration.
-	 * 
+	 *
 	 * @param date
 	 * @param css
 	 * @return the string representation of the duration OR the css class
 	 */
 	private String timeAgo(Date date, boolean css) {
-		if (isToday(date) || isYesterday(date)) {
+		if (isToday(date, timezone) || isYesterday(date, timezone)) {
 			int mins = minutesAgo(date, true);
 			if (mins >= 120) {
 				if (css) {
@@ -267,7 +279,7 @@
 			}
 		}
 	}
-	
+
 	public String inFuture(Date date) {
 		long diff = date.getTime() - System.currentTimeMillis();
 		if (diff > ONEDAY) {
@@ -283,7 +295,7 @@
 			}
 		}
 	}
-	
+
 	private String translate(String key, String defaultValue) {
 		String value = defaultValue;
 		if (translation != null && translation.containsKey(key)) {
@@ -294,7 +306,7 @@
 		}
 		return value;
 	}
-	
+
 	private String translate(int val, String key, String defaultPattern) {
 		String pattern = defaultPattern;
 		if (translation != null && translation.containsKey(key)) {
@@ -308,7 +320,7 @@
 
 	/**
 	 * Convert a frequency string into minutes.
-	 * 
+	 *
 	 * @param frequency
 	 * @return minutes
 	 */

--
Gitblit v1.9.1