Remove uses of Time. am: 909a0763c6
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Messaging/+/2149693
Change-Id: Ifb1497b8c212866284a9c138e58612aa7bde3f28
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/com/android/messaging/util/Dates.java b/src/com/android/messaging/util/Dates.java
index d012dfd..49f0c7f 100644
--- a/src/com/android/messaging/util/Dates.java
+++ b/src/com/android/messaging/util/Dates.java
@@ -18,13 +18,16 @@
import android.content.Context;
import android.text.format.DateUtils;
-import android.text.format.Time;
import com.android.messaging.Factory;
import com.android.messaging.R;
import com.google.common.annotations.VisibleForTesting;
import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
+import java.time.ZoneId;
import java.util.Date;
import java.util.Locale;
@@ -265,16 +268,11 @@
return String.format(format, count);
}
- private static synchronized long getNumberOfDaysPassed(final long date1, final long date2) {
- if (sThenTime == null) {
- sThenTime = new Time();
- }
- sThenTime.set(date1);
- final int day1 = Time.getJulianDay(date1, sThenTime.gmtoff);
- sThenTime.set(date2);
- final int day2 = Time.getJulianDay(date2, sThenTime.gmtoff);
- return Math.abs(day2 - day1);
+ private static long getNumberOfDaysPassed(final long date1, final long date2) {
+ LocalDateTime dateTime1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(date1),
+ ZoneId.systemDefault());
+ LocalDateTime dateTime2 = LocalDateTime.ofInstant(Instant.ofEpochMilli(date2),
+ ZoneId.systemDefault());
+ return Math.abs(ChronoUnit.DAYS.between(dateTime2, dateTime1));
}
-
- private static Time sThenTime;
}