DateTimeParseException on specific device

46 Views Asked by At

Has anyone encountered DateTimeParseException on specific devices? I've encountered a crash that happens on a Samsung J7, Android 9 whenever this String is parsed 3/30/2023 12:00:00 AM.

The parsing code looks like this:

fun numberOfDaysBetweenToday(
    dateTime: String,
    clock: Clock,
    zoneId: ZoneId,
    dateTimeFormatter: DateTimeFormatter
): Long {
    val now = Instant.now(clock).atZone(zoneId)
    val other = LocalDateTime.parse(dateTime, dateTimeFormatter).atZone(zoneId)
    return ChronoUnit.DAYS.between(now, other)
}

And I use this function like this:

numberOfDaysBetweenToday("3/30/2023 12:00:00 AM", ZoneId.of("Asia/Manila"), DateTimeFormatter.ofPattern("M/dd/yyyy h:mm:ss a"))

It works on the emulator (Pixel 4), and on my latest Samsung device (Samsung A52s), but on this specific actual device, I'm getting DateTimeParseException: Text '3/30/2023 12:00:00 AM' could not be parsed at index 19

Has anyone encountered something like this?

0

There are 0 best solutions below