JakeWharton / ThreeTenABP

An adaptation of the JSR-310 backport for Android.
Apache License 2.0
3.55k stars 133 forks source link

threeTenABP fails when java 8 version is working #81

Closed huntj88 closed 6 years ago

huntj88 commented 6 years ago

The only thing i changed was the imports from the java.time package to org.threeten.bp package and this code snippet failed to run. I've removed all of the extra stuff to get the smallest bit of code that fails.

    val formatter = DateTimeFormatterBuilder()
            .appendOptional(DateTimeFormatter.ofPattern("EEE, dd MMM yyyy H:mm:ss z"))
            .toFormatter()
            .withZone(ZoneId.of("UTC"))

    val instant = try {
        ZonedDateTime.parse("Wed, 09 May 2018 0:00:00 EDT", formatter).toInstant()
    } catch (e: DateTimeParseException) {
        e.printStackTrace()
        null
    }

    println(instant)
org.threeten.bp.format.DateTimeParseException: Text 'Wed, 09 May 2018 0:00:00 EDT' could not be parsed, unparsed text found at index 0
    at org.threeten.bp.format.DateTimeFormatter.parseToBuilder(DateTimeFormatter.java:1590)
    at org.threeten.bp.format.DateTimeFormatter.parse(DateTimeFormatter.java:1491)
    at org.threeten.bp.ZonedDateTime.parse(ZonedDateTime.java:562)
    at test.TestKt.main(Test.kt:89)
JakeWharton commented 6 years ago

You'll want to file this on https://github.com/ThreeTen/threetenbp. This library is only a repackaging of the timezone database and a dependency on that library.