Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8046416

Unable to parse an Instant from fields

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8u20
    • 8u20
    • core-libs
    • b20

        The fix for JDK-8033662 enabled a ZonedDateTime to be parsed when withZone() is used. Unfortunately, the fix did not allow an Instant to be parsed. More generally, there is no current way to parse an instant except using the appendInstant() method of the formatter builder.

            @Test
            public void test_parse_Instant_withZone1() {
                DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss ").appendZoneId().toFormatter();
                TemporalAccessor acc = fmt.parse("2014-06-30 01:02:03 Europe/Paris");
                Instant actual = Instant.from(acc);
                assertEquals(actual, ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS).toInstant());
            }

            @Test
            public void test_parse_Instant_withZone2() {
                DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(PARIS);
                TemporalAccessor acc = fmt.parse("2014-06-30 01:02:03");
                Instant actual = Instant.from(acc);
                assertEquals(actual, ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS).toInstant());
            }

        Tests fail in the from() method because it does not make available INSTANT_SECONDS even though sufficient data is available.

              rriggs Roger Riggs
              scolebourne Stephen Colebourne
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: