0

I am defining a formatter as follows:

private static final DateTimeFormatter FORMATTER =
  new DateTimeFormatterBuilder()
      .parseCaseInsensitive()
      .appendLiteral("y")
      .appendValue(IsoFields.WEEK_BASED_YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
      .appendLiteral("w")
      .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2)
      .toFormatter();

I am inputting the following strings which I believe should be valid using the following parsing call:

LocalDate.parse(inputString, FORMATTER).atStartOfDay()

With the following values of inputString:

  • y2019w52
  • y2020w01
  • y2019w03

All are throwing parsing errors, for example:

Text 'y2019w03' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {WeekOfWeekBasedYear=3, WeekBasedYear=2019},ISO of type java.time.format.Parsed

any ideas?

75inchpianist
  • 4,074
  • 1
  • 20
  • 38
  • 1
    You need to add `.parseDefaulting(ChronoField.DAY_OF_WEEK, 1)` to the `DateTimeFormatterBuilder` chain. – Andreas Jun 23 '21 at 00:59

0 Answers0