DateTimeService unable to parse date 01-01-1970 in UTC
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.8k
- Forks
- 717
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 3
Description
Description:
In the DateField component if I introduce the date 01-01-1970 with the keyboard I've got a 'Date format not recognized' error and
in the console I've got "java.lang.IllegalArgumentException: Parsing of '01-01-1970' failed".
This only happens if I have the Windows in UTC time.
I take a look in the code and find why this is happens, in the class com.vaadin.client.DateTimeService method parseDate (line 485) you have this if:
// Some version of Firefox sets the timestamp to 0 if parsing fails.
if (date != null && date.getTime() == 0) {
throw new IllegalArgumentException(
"Parsing of '" + dateString + "' failed");
}
the date 01-01-1970 in UTC it's zero, so it always throw the exception.
For example
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date d = sdf.parse("01-01-1970");
System.out.println(d.getTime()); // prints 0
System.out.println(new Date(0).getTime()); // prints 0
Tested with:
Vaadin 8.0.3
Windows 7
Chrome 56
Windows Timezone: (UTC+00:00) Dublin, Edimburgo, Lisboa, Londres
Windows Regional Settings: Portugal dd-MM-yyyy
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in com.vaadin.client.DateTimeService.parseDate around line 485 and reproduce the DateField input with UTC timezone and the 01-01-1970 value. Check the existing parsing-failure handling and add coverage for this epoch date; done means valid UTC input is accepted while genuinely failed parsing still reports an error.
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
- Mostly clear
- Newbie friendliness
- 45/100