ISO8601Utils assumes local timezone while parsing "yyyy-MM-dd" dates
- Dominant language
- Java
- Stars
- 24.2k
- Forks
- 4.5k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 12
Description
Parsing a "yyyy-MM-dd" date without a timezone using
```
ISO8601Utils.parse(dateString, ParsePosition(0)).toInstant()
```
applies a timezone from a default locale which leads to an incorrect result.
Input: `2019-03-20`
Actual Output: `2019-03-19T23:00:00Z` when a system default locale is UTC+01
Expected Output: `2019-03-20T00:00:00Z` regardless of the system locale
I think the problem is that `GregorianCalendar` must be preconfigured with the UTC timezone, and it's not done in `ISO8601Utils`:
```
// if the value has no time component (and no time zone), we are done
boolean hasT = checkOffset(date, offset, 'T');
if (!hasT && (date.length() <= offset)) {
Calendar calendar = new GregorianCalendar(year, month - 1, day);
pos.setIndex(offset);
return calendar.getTime();
}
```
Contributor guide
Assessment
This issue has not been assessed yet.