Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISO8601Utils assumes local timezone while parsing "yyyy-MM-dd" dates #1511

Open
roman-tikonov opened this issue Apr 11, 2019 · 2 comments
Open
Labels

Comments

@roman-tikonov
Copy link

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();
            }
@pavlo-zin
Copy link

Any updates on this?

@eamonnmcmanus
Copy link
Member

It's certainly regrettable that the code is the way it is, but as I mentioned in #2480 we can't change it without breaking existing deployments. It's an internal class, so really I think what we're talking about is its use in DateTypeAdapter and DefaultDateTypeAdapter. I think we should probably have a configuration option that causes Date to be serialized following ISO 8601, and that might also imply that a deserialized date/time without a timezone defaults to UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants