Como converter DateTimeFormat.forStyle () do Joda-Time para JSR 310 JavaTime?

Eu estou trabalhando na conversão Grails Joda-Time plugin paraJavaTime.

E eu tenho o código de tempo Joda antigo assim:

    def style
    switch (type) {
        case LocalTime:
            style = '-S'
            break
        case LocalDate:
            style = 'S-'
            break
        default:
            style = 'SS'
    }
    Locale locale = LocaleContextHolder.locale
    return DateTimeFormatter.ofPattern(style, locale).withResolverStyle(ResolverStyle.LENIENT)

Como posso convertê-lo para JSR 310? Não consigo encontrar nada parecido com o métodoforStyle (estilo String) que aceita estilo.

UPD Encontrei uma solução alternativa:

        Locale locale = LocaleContextHolder.locale
        DateTimeFormatter formatter
        switch (type) {
            case LocalTime:
                formatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(locale)
                break
            case LocalDate:
                formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withLocale(locale)
                break
            default:
                formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(locale)
        }
        return formatter

Mas falha deInstant tipo. Especificação de Spock para reproduzir:

def 'Instant locale formatting'() {
    given:
    Instant inst = Instant.ofEpochMilli(92554380000L)
    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(UK)
    expect:
    formatter.format(inst) == "07/12/72 05:33"
}

Este teste falha com erro:

java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: DayOfMonth
    at java.time.Instant.getLong(Instant.java:603)
    at java.time.format.DateTimePrintContext$1.getLong(DateTimePrintContext.java:205)
    at java.time.format.DateTimePrintContext.getValue(DateTimePrintContex,t.java:298)
    at java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2543)
    at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2182)
    at java.time.format.DateTimeFormatterBuilder$LocalizedPrinterParser.format(DateTimeFormatterBuilder.java:4350)
    at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2182)
    at java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1744)
    at java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1718)

Então, por que o formatador não pode formatarInstant?

questionAnswers(2)

yourAnswerToTheQuestion