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

Unable to parse an Instant from fields

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u20
    • Fix Version/s: 8u20
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b20

      Backports

        Description

        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.

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved: