Skip to content

Add java.time Instant, Year, YearMonth and MonthDay support to DateTimeConverter - #2221

Open
BalusC wants to merge 1 commit into
5.0from
issue_2211
Open

Add java.time Instant, Year, YearMonth and MonthDay support to DateTimeConverter#2221
BalusC wants to merge 1 commit into
5.0from
issue_2211

Conversation

@BalusC

@BalusC BalusC commented Jul 30, 2026

Copy link
Copy Markdown
Member

The type attribute of DateTimeConverter / <f:convertDateTime> now also accepts "instant", "year", "yearMonth" and "monthDay", corresponding to java.time.Instant, java.time.Year, java.time.YearMonth and java.time.MonthDay.

Default format

None of these four types can be formatted or parsed with a localized date/time style — DateTimeFormatter.ofLocalizedDate() throws UnsupportedTemporalTypeException for all of them (missing DayOfMonth, or YearOfEra for MonthDay), and java.time exposes no API for the CLDR available-formats (yMM, Md) that would be needed to derive a localized year-month or month-day pattern. Hence dateStyle and timeStyle are ignored for these types and, when no pattern is specified, the ISO 8601 form of the type is used:

type default format equals
instant DateTimeFormatter.ISO_INSTANT Instant.toString() / Instant.parse()
year uuuu Year.toString() / Year.parse()
yearMonth uuuu-MM YearMonth.toString() / YearMonth.parse()
monthDay --MM-dd MonthDay.toString() / MonthDay.parse()

This follows the existing offsetTime/offsetDateTime/zonedDateTime types, which also use a fixed ISO formatter and ignore the styles. Parsing stays strict, as the spec requires: ResolverStyle.STRICT with IsoChronology, so 2026-13 and --02-30 are rejected while --02-29 is accepted.

Time zone

An Instant carries no zone, so for the type instant the timeZone property is passed to the underlying DateTimeFormatter. Without it a pattern containing date or time fields cannot be resolved and formatting blows up. ISO_INSTANT itself always renders in UTC regardless, which is documented.

Message selection

The four new types are added to the message selection in getAsObject(). A type absent from that switch falls through the catch without throwing, which would have silently converted unparseable input to null.

Not included

java.time.Duration and java.time.Period from the issue are deliberately left out: they are TemporalAmount, not TemporalAccessor, so DateTimeFormatter cannot handle them at all. They warrant their own converter, to be discussed separately.

Tests

  • DateTimeConverterTest: ISO round-trip per type, explicit patterns, instant with a pattern in Europe/Amsterdam, leap day, and ConverterException on unparseable input. 153 tests green in the api module.
  • TCK: Spec2211IT + spec2211.xhtml + Spec2211Bean under tck/faces50/converters, covering the same through <f:convertDateTime>. Compiles; not yet run against a container.

Closes #2211

🤖 Generated with Claude Code (Opus 5)

…meConverter

The type attribute now also accepts "instant", "year", "yearMonth" and
"monthDay". None of these types can be formatted or parsed with a localized
date/time style, so dateStyle and timeStyle are ignored for them and the ISO
8601 form of the type is used when no pattern is specified: ISO_INSTANT for
instant, "uuuu" for year, "uuuu-MM" for yearMonth and "--MM-dd" for monthDay.
This follows the existing offsetTime/offsetDateTime/zonedDateTime types, which
also use a fixed ISO formatter.

An Instant carries no zone, so for that type the timeZone property is passed to
the formatter, which makes a pattern containing date or time fields resolvable.

The new types are also added to the message selection in getAsObject, which
would otherwise swallow the parse exception and silently convert bad input to
null.

Closes #2211

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant