I've created a vaadin grid and used the setItems method in combination with a custom jpa repository that returns a paged stream. The problem appears when the grid has to show a date with a specific date (2019-12-31), it will automatically show "31.12.2020", looks like the date is somehow jumping to the next year.
here the grid
private Grid<Budget> createGrid() {
Grid<Budget> grid = new Grid<>(Budget.class, false);
grid.setPageSize(100);
grid.setSortableColumns();
grid.addColumn(new LocalDateRenderer<>(Budget::getValidfrom, "dd.MM.YYYY")).setHeader("Gültig von");
grid.addColumn(new LocalDateRenderer<>(Budget::getValidto, "dd.MM.YYYY")).setHeader("Gültig bis");
for (Grid.Column<Budget> c : grid.getColumns()) {
c.setAutoWidth(true).setFlexGrow(2);
}
return grid;
}
here how I fill the grid
grid.setItems(query -> service.getLimitData(filter, query.getPage(), query.getPageSize()).stream());
dataset in database
dataset in vaadin grid
CodePudding user response:
tl;dr
Change YYYY
to uuuu
to correct your formatting pattern.
Your issue has nothing to do with Vaadin specifically. Date formatting is standard Java.
Week-based year versus calendar year
Your formatting code is incorrect.
Uppercase YYYY
means a week-based year, not a calendar year. That code uses the ISO 8601 definition of weeks and week-based year: Week starts on Monday, runs a full 7 days, and first week contains the first Thursday of the calendar year. So the first and last weeks of the week-based year may have a few days from the previous/next calendar year. So the unexpected year you encountered is a feature, not a bug.
For calendar-year, use lowercase yyyy
or uuuu
.
These formatting pattern codes are documented on the Javadoc for the DateTimeFormatter
class.