Loading core/java/android/text/format/DateUtils.java +16 −9 Original line number Diff line number Diff line Loading @@ -32,6 +32,9 @@ import libcore.icu.LocaleData; import libcore.icu.RelativeDateTimeFormatter; import java.io.IOException; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Calendar; import java.util.Date; import java.util.Formatter; Loading Loading @@ -502,17 +505,21 @@ public class DateUtils * @return true if the supplied when is today else false */ public static boolean isToday(long when) { Time time = new Time(); time.set(when); return isSameDate(when, System.currentTimeMillis()); } private static boolean isSameDate(long oneMillis, long twoMillis) { ZoneId zoneId = ZoneId.systemDefault(); Instant oneInstant = Instant.ofEpochMilli(oneMillis); LocalDateTime oneLocalDateTime = LocalDateTime.ofInstant(oneInstant, zoneId); int thenYear = time.year; int thenMonth = time.month; int thenMonthDay = time.monthDay; Instant twoInstant = Instant.ofEpochMilli(twoMillis); LocalDateTime twoLocalDateTime = LocalDateTime.ofInstant(twoInstant, zoneId); time.set(System.currentTimeMillis()); return (thenYear == time.year) && (thenMonth == time.month) && (thenMonthDay == time.monthDay); return (oneLocalDateTime.getYear() == twoLocalDateTime.getYear()) && (oneLocalDateTime.getMonthValue() == twoLocalDateTime.getMonthValue()) && (oneLocalDateTime.getDayOfMonth() == twoLocalDateTime.getDayOfMonth()); } /** Loading Loading
core/java/android/text/format/DateUtils.java +16 −9 Original line number Diff line number Diff line Loading @@ -32,6 +32,9 @@ import libcore.icu.LocaleData; import libcore.icu.RelativeDateTimeFormatter; import java.io.IOException; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Calendar; import java.util.Date; import java.util.Formatter; Loading Loading @@ -502,17 +505,21 @@ public class DateUtils * @return true if the supplied when is today else false */ public static boolean isToday(long when) { Time time = new Time(); time.set(when); return isSameDate(when, System.currentTimeMillis()); } private static boolean isSameDate(long oneMillis, long twoMillis) { ZoneId zoneId = ZoneId.systemDefault(); Instant oneInstant = Instant.ofEpochMilli(oneMillis); LocalDateTime oneLocalDateTime = LocalDateTime.ofInstant(oneInstant, zoneId); int thenYear = time.year; int thenMonth = time.month; int thenMonthDay = time.monthDay; Instant twoInstant = Instant.ofEpochMilli(twoMillis); LocalDateTime twoLocalDateTime = LocalDateTime.ofInstant(twoInstant, zoneId); time.set(System.currentTimeMillis()); return (thenYear == time.year) && (thenMonth == time.month) && (thenMonthDay == time.monthDay); return (oneLocalDateTime.getYear() == twoLocalDateTime.getYear()) && (oneLocalDateTime.getMonthValue() == twoLocalDateTime.getMonthValue()) && (oneLocalDateTime.getDayOfMonth() == twoLocalDateTime.getDayOfMonth()); } /** Loading