Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3315)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java

Issue 2701253006: Download Home : Suggested pages header selection (Closed)
Patch Set: nits and fixed background color Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
index b989159158052b5abf18049dd18069fc7d1783b1..6099145a7be22a8cadef771ebb3d00c9c9d49c42 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
@@ -56,6 +56,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.text.NumberFormat;
import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
import java.util.List;
import java.util.Locale;
@@ -742,4 +744,25 @@ public class DownloadUtils {
return MIME_TYPE_VIDEO.equals(pieces[0]);
}
+
+ /**
+ * Given two timestamps, calculates if both occur on the same date.
+ * @return True if they belong in the same day. False otherwise.
+ */
+ public static boolean isSameDay(long timestamp1, long timestamp2) {
+ return getDateAtMidnight(timestamp1).equals(getDateAtMidnight(timestamp2));
+ }
+
+ /**
+ * Calculates the {@link Date} for midnight of the date represented by the |timestamp|.
+ */
+ public static Date getDateAtMidnight(long timestamp) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(timestamp);
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+ return cal.getTime();
+ }
}

Powered by Google App Engine
This is Rietveld 408576698