diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2022-08-11 18:37:42 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-08-11 18:37:42 +0000 |
commit | 7764a0fa00e092e22b9838fc8a5f789e64c5d279 (patch) | |
tree | 9f382e3685397526cec3272c18e01f6749a11542 | |
parent | 547b750f8192f58283d5f63a5a4fa86bd3060339 (diff) | |
parent | 8ae2abef7dcf8574812bb0c0b0bb9a7be4c0c56d (diff) | |
download | Dialer-7764a0fa00e092e22b9838fc8a5f789e64c5d279.tar.gz |
Merge "Remove Time use." am: 34db0a318b am: 40451798aa am: 8ae2abef7d
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Dialer/+/2162292
Change-Id: I9d04a1ed1bde3ca2fc13d252f4db756ddb1c7bba
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | java/com/android/contacts/common/util/DateUtils.java | 18 | ||||
-rw-r--r-- | java/com/android/dialer/app/calllog/CallLogGroupBuilder.java | 7 |
2 files changed, 13 insertions, 12 deletions
diff --git a/java/com/android/contacts/common/util/DateUtils.java b/java/com/android/contacts/common/util/DateUtils.java index 09d52bce8..d5147eb9b 100644 --- a/java/com/android/contacts/common/util/DateUtils.java +++ b/java/com/android/contacts/common/util/DateUtils.java @@ -16,7 +16,11 @@ package com.android.contacts.common.util; -import android.text.format.Time; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.temporal.ChronoUnit; + /** Utility methods for processing dates. */ public class DateUtils { @@ -30,13 +34,9 @@ public class DateUtils { * @param date2 Second date to check. * @return The absolute difference in days between the two dates. */ - public static int getDayDifference(Time time, long date1, long date2) { - time.set(date1); - int startDay = Time.getJulianDay(date1, time.gmtoff); - - time.set(date2); - int currentDay = Time.getJulianDay(date2, time.gmtoff); - - return Math.abs(currentDay - startDay); + public static int getDayDifference(ZoneId timeZone, long date1, long date2) { + LocalDate localDate1 = Instant.ofEpochMilli(date1).atZone(timeZone).toLocalDate(); + LocalDate localDate2 = Instant.ofEpochMilli(date2).atZone(timeZone).toLocalDate(); + return Math.abs((int) ChronoUnit.DAYS.between(localDate2, localDate1)); } } diff --git a/java/com/android/dialer/app/calllog/CallLogGroupBuilder.java b/java/com/android/dialer/app/calllog/CallLogGroupBuilder.java index e52591174..805ee64c5 100644 --- a/java/com/android/dialer/app/calllog/CallLogGroupBuilder.java +++ b/java/com/android/dialer/app/calllog/CallLogGroupBuilder.java @@ -23,7 +23,6 @@ import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; -import android.text.format.Time; import com.android.contacts.common.util.DateUtils; import com.android.dialer.calllogutils.CallbackActionHelper; import com.android.dialer.calllogutils.CallbackActionHelper.CallbackAction; @@ -31,6 +30,8 @@ import com.android.dialer.compat.telephony.TelephonyManagerCompat; import com.android.dialer.inject.ApplicationContext; import com.android.dialer.phonenumbercache.CallLogQuery; import com.android.dialer.phonenumberutil.PhoneNumberHelper; + +import java.time.ZoneId; import java.util.Objects; /** @@ -56,7 +57,7 @@ public class CallLogGroupBuilder { /** Day grouping for calls which occurred before last week. */ public static final int DAY_GROUP_OTHER = 2; /** Instance of the time object used for time calculations. */ - private static final Time TIME = new Time(); + private static final ZoneId TIME_ZONE = ZoneId.systemDefault(); private final Context appContext; /** The object on which the groups are created. */ @@ -255,7 +256,7 @@ public class CallLogGroupBuilder { * @return The date group the call belongs in. */ private int getDayGroup(long date, long now) { - int days = DateUtils.getDayDifference(TIME, date, now); + int days = DateUtils.getDayDifference(TIME_ZONE, date, now); if (days == 0) { return DAY_GROUP_TODAY; |