-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Bug Parse Date 1966-11-01 #2539
Comments
This error seems to be happening since Gson 2.9.1. Stack trace:
|
The exception should have a cause ("Caused by: ..."), could you please include that part of the stack trace as well? I assume #2134 might be responsible for this issue, but I could not reproduce it yet locally, for me no exception occurred. Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
System.out.println(gson.fromJson("1966-11-01", Date.class)); Could you also please provide the output of this? System.out.println(Locale.getDefault());
System.out.println(TimeZone.getDefault()); Maybe the default locale or timezone on your PC somehow affects the date parsing. Could be related to #1511, that your default timezone does not consider 1966-11-01 to be a valid date (?). Footnotes
|
Hello, The problem only occurs when running on a device, or via Roboletric in tests. Execute:
Result:
|
Thanks! This seems to be caused indeed by your default timezone. If I add the following to the test code above TimeZone.setDefault(TimeZone.getTimeZone("America/Sao_Paulo")); It fails with:
Not sure if this can be fixed in any way other than reverting #2134 1, which would mean Gson would fail to detect dates which are invalid for all timezones, or fixing #1511, which might negatively affect other users. As pointed out in the discussion in #2480, it might be better if you switched from @eamonnmcmanus, what do you think? Footnotes
|
Getting same error for 1982-01-01 and 1933-01-01 |
Gson version
Version: 2.10.1
Java / Android version
Android target sdk 33
Used tools
Description
Failure in parse date '1966-11-01'
Expected behavior
Failed parsing '1966-11-01' as Date; at path $.birthday
If it's a day's difference from success
The text was updated successfully, but these errors were encountered: