mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Java: Update help and description of java/suspicious-date-format.
This commit is contained in:
@@ -6,9 +6,12 @@
|
||||
|
||||
<overview>
|
||||
<p>
|
||||
Some <code>SimpleDateFormat</code> patterns might not work correctly at the end of the calendar
|
||||
year, due to use of the <code>Y</code> placeholder (representing the ISO 8601 week year), rather
|
||||
than <code>y</code> representing the actual year.
|
||||
The Java <code>SimpleDateFormat</code> class provides many placeholders so that you can define
|
||||
precisely the date format required. However, this also makes it easy to define a pattern that
|
||||
doesn't behave exactly as you intended. The most common mistake is to use the <code>Y</code>
|
||||
placeholder (which represents the ISO 8601 week year), rather than <code>y</code> (which
|
||||
represents the actual year). In this case, the date reported will appear correct until the end
|
||||
of the year, when the "week year" may differ from the actual year.
|
||||
</p>
|
||||
</overview>
|
||||
|
||||
@@ -24,6 +27,9 @@ than <code>y</code> representing the actual year.
|
||||
On the 30th of December 2019, this code will output "2020-12-30", rather than the intended "2019-12-30".
|
||||
</p>
|
||||
<sample src="SuspiciousDateFormat.java" />
|
||||
<p>
|
||||
The correct pattern in this case would be <code>yyyy-MM-dd</code> instead of <code>YYYY-MM-dd</code>.
|
||||
</p>
|
||||
</example>
|
||||
|
||||
<references>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @name Suspicious date format
|
||||
* @description Some date format patterns don't work as they might seem.
|
||||
* @description Using a data format that includes both 'M' and 'Y' is likely to give unexpected results.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @precision high
|
||||
|
||||
Reference in New Issue
Block a user