Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vaadin Grid shows wrong year if date is the 31th of December

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

grid.setItems(query -> service.getLimitData(filter, query.getPage(), query.getPageSize()).stream());

dataset in database
enter image description here
dataset in vaadin grid
enter image description here

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading