vaadin / vaadin/framework

DateField component trims info about time from date range validation

Open
#7,599 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
1.8k
Forks
717
Avg merge
2d 6h
Merged PRs (30d)
3

Description

Originally by Ellrohir


I am using two Vaadin DateFields for FROM-TO interval input from user. I naturally want TO date being after FROM date. So I put a ValueChangeListner on each that sets RangeStart/RangeEnd to each other DateField. The resolution of both DateFields is Resolution.MINUTE, because I need precision in minutes.

I have found the automatic validation does't work when user inputs TO date for the same day as FROM date, but between 00:00 and FROM input (so TO 2016-04-14 10:24 passes the test when FROM is 2016-04-15 10:25). I have tracked down the code in Vaadin and found method DateField.getRangeStart(Resolution forResolution). This method strips info about time from input, so it returns 2016-04-14 00:00 instead of 2016-04-14 10:24. Then the valiadion obviously must fail...

The reason is this part of code:

        if (forResolution == Resolution.YEAR) {
            startCal.set(startCal.get(Calendar.YEAR), 0, 1, 0, 0, 0);
        } else if (forResolution == Resolution.MONTH) {
            startCal.set(startCal.get(Calendar.YEAR),
                    startCal.get(Calendar.MONTH), 1, 0, 0, 0);
        } else {
            startCal.set(startCal.get(Calendar.YEAR),
                    startCal.get(Calendar.MONTH), startCal.get(Calendar.DATE),
                    0, 0, 0);
        }

namely the else branch

            startCal.set(startCal.get(Calendar.YEAR),
                    startCal.get(Calendar.MONTH), startCal.get(Calendar.DATE),
                    0, 0, 0);

When I have Resolution.MINUTE, the program falls into this branch and the Calendar is set to 00:00:00...then startCal.getTime() is returned and I am short of my time info...

In my code I can obviously add aditional validation. But I think this should be fixed to work properly respecting the actual Resolution of particular DateField.

I still see the same code in [https://github.com/vaadin/vaadin/blob/master/server/src/com/vaadin/ui/DateField.java] so it should be just me and my old Vaadin version.

Thanks for any feedback. I may be also wrong for some reason.


Imported from https://dev.vaadin.com/ issue #19739

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in server/src/com/vaadin/ui/DateField.java at getRangeStart(Resolution forResolution), focusing on the else branch shown in the issue. Verify how Resolution.MINUTE is handled and confirm the range validation preserves the entered time; the issue is done when same-day FROM and TO values are validated by their actual minute-level ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.