Skip to content

Commit 484333b

Browse files
committed
Java: Update help and description of java/suspicious-date-format.
1 parent 0e8d435 commit 484333b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

java/ql/src/Likely Bugs/Likely Typos/SuspiciousDateFormat.qhelp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
<overview>
88
<p>
9-
Some <code>SimpleDateFormat</code> patterns might not work correctly at the end of the calendar
10-
year, due to use of the <code>Y</code> placeholder (representing the ISO 8601 week year), rather
11-
than <code>y</code> representing the actual year.
9+
The Java <code>SimpleDateFormat</code> class provides many placeholders so that you can define
10+
precisely the date format required. However, this also makes it easy to define a pattern that
11+
doesn't behave exactly as you intended. The most common mistake is to use the <code>Y</code>
12+
placeholder (which represents the ISO 8601 week year), rather than <code>y</code> (which
13+
represents the actual year). In this case, the date reported will appear correct until the end
14+
of the year, when the "week year" may differ from the actual year.
1215
</p>
1316
</overview>
1417

@@ -24,6 +27,9 @@ than <code>y</code> representing the actual year.
2427
On the 30th of December 2019, this code will output "2020-12-30", rather than the intended "2019-12-30".
2528
</p>
2629
<sample src="SuspiciousDateFormat.java" />
30+
<p>
31+
The correct pattern in this case would be <code>yyyy-MM-dd</code> instead of <code>YYYY-MM-dd</code>.
32+
</p>
2733
</example>
2834

2935
<references>

java/ql/src/Likely Bugs/Likely Typos/SuspiciousDateFormat.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Suspicious date format
3-
* @description Some date format patterns don't work as they might seem.
3+
* @description Using a data format that includes both 'M' and 'Y' is likely to give unexpected results.
44
* @kind problem
55
* @problem.severity warning
66
* @precision high

0 commit comments

Comments
 (0)