-
Notifications
You must be signed in to change notification settings - Fork 737
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
Prevent more common DateTimeFormatter issues #1462
Comments
Isn't that already taken care of by https://errorprone.info/bugpattern/MisusedWeekYear? |
@tbroyer Yes, I missed that and it handles the Week Based Year. Thanks. Less common I'm sure, but maybe there should be a MisuedDayOfYear around using
I confirmed that the following does not throw a compile warning with errorprone.
|
Nice suggestion, thanks! This has been implemented and sent out for review internally. Should be in a future version. |
Fixes #1462 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=289114572
Fixes external #1462 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=289114572
Fixes external #1462 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=289114572
Description of the problem / feature request:
Create new bug pattern which alerts if a java.time.format.DateTimeFormatter is created using capital
Y
(likeYYYY-dd-MM
) without aw
indicating that it is using week based year.https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
Feature requests: what underlying problem are you trying to solve with this feature?
Prevent users from making a mistake with formatting for example the following code
Will Print
This can be a common mistake.
It may also be useful to alert on other patterns such as
D
(day of year) in combination withM
(month) whereDateTimeFormatter.ofPattern("YYYY-MM-DD").format(LocalDate.of(2019,12,31)
will produce2020-12-365
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
What version of Error Prone are you using?
2.3.4
Have you found anything relevant by searching the web?
Somewhat of a common issue. Jodatime used
x
for week based year to limit confusion.https://www.reddit.com/r/java/comments/ehucj3/important_at_this_time_of_the_year_beware_of_yyyy/
The text was updated successfully, but these errors were encountered: