Skip to content

Commit fef2e26

Browse files
authored
Merge pull request #14 from javaevolved/copilot/fix-java-code-flaws
Fix date formatter patterns and text block equivalence
2 parents 445831a + df8c9ef commit fef2e26

File tree

8 files changed

+10
-12
lines changed

8 files changed

+10
-12
lines changed

data/snippets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"oldApproach": "String Concatenation",
4646
"modernApproach": "Text Blocks",
4747
"oldCode": "String json = \"{\\n\" +\n \" \\\"name\\\": \\\"Duke\\\",\\n\" +\n \" \\\"age\\\": 30\\n\" +\n \"}\";",
48-
"modernCode": "String json = \"\"\"\n {\n \"name\": \"Duke\",\n \"age\": 30\n }\n \"\"\";",
48+
"modernCode": "String json = \"\"\"\n {\n \"name\": \"Duke\",\n \"age\": 30\n }\"\"\";",
4949
"summary": "Write multiline strings naturally with triple-quote text blocks.",
5050
"explanation": "Text blocks let you write multiline strings exactly as they appear. No more escaping quotes or adding \\n. The compiler strips incidental indentation automatically.",
5151
"whyModernWins": [
@@ -1133,7 +1133,7 @@
11331133
"oldApproach": "Escaped Strings",
11341134
"modernApproach": "Text Blocks",
11351135
"oldCode": "String sql =\n \"SELECT u.name, u.email\\n\" +\n \"FROM users u\\n\" +\n \"WHERE u.active = true\\n\" +\n \"ORDER BY u.name\";",
1136-
"modernCode": "String sql = \"\"\"\n SELECT u.name, u.email\n FROM users u\n WHERE u.active = true\n ORDER BY u.name\n \"\"\";",
1136+
"modernCode": "String sql = \"\"\"\n SELECT u.name, u.email\n FROM users u\n WHERE u.active = true\n ORDER BY u.name\"\"\";",
11371137
"summary": "Write SQL, JSON, and HTML as they actually look.",
11381138
"explanation": "Text blocks make embedded languages readable. Copy SQL from your database tool and paste it directly. The closing delimiter position controls indentation stripping.",
11391139
"whyModernWins": [
@@ -2425,7 +2425,7 @@
24252425
"oldApproach": "SimpleDateFormat",
24262426
"modernApproach": "DateTimeFormatter",
24272427
"oldCode": "// Not thread-safe!\nSimpleDateFormat sdf =\n new SimpleDateFormat(\"yyyy-MM-dd\");\nString formatted = sdf.format(date);\n// Must synchronize for concurrent use",
2428-
"modernCode": "DateTimeFormatter fmt =\n DateTimeFormatter.ofPattern(\n \"yyyy-MM-dd\");\nString formatted =\n LocalDate.now().format(fmt);\n// Thread-safe, immutable",
2428+
"modernCode": "DateTimeFormatter fmt =\n DateTimeFormatter.ofPattern(\n \"uuuu-MM-dd\");\nString formatted =\n LocalDate.now().format(fmt);\n// Thread-safe, immutable",
24292429
"summary": "Format dates with thread-safe, immutable DateTimeFormatter.",
24302430
"explanation": "DateTimeFormatter is immutable and thread-safe, unlike SimpleDateFormat. It can be stored as a constant and shared. Predefined formatters like ISO_LOCAL_DATE are available for common formats.",
24312431
"whyModernWins": [

date-formatting.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ <h1>Date formatting</h1>
138138
<div class="compare-code">
139139
<pre class="code-text">DateTimeFormatter fmt =
140140
DateTimeFormatter.ofPattern(
141-
&quot;yyyy-MM-dd&quot;);
141+
&quot;uuuu-MM-dd&quot;);
142142
String formatted =
143143
LocalDate.now().format(fmt);
144144
// Thread-safe, immutable</pre>

duration-and-period.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ <h3>Date formatting</h3>
262262
<div class="mini-label">Java 8+</div>
263263
<pre class="code-text">DateTimeFormatter fmt =
264264
DateTimeFormatter.ofPattern(
265-
&quot;yyyy-MM-dd&quot;);
265+
&quot;uuuu-MM-dd&quot;);
266266
String formatted =
267267
LocalDate.now().format(fmt);
268268
// Thread-safe, immutable</pre>

hex-format.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ <h3>Date formatting</h3>
228228
<div class="mini-label">Java 8+</div>
229229
<pre class="code-text">DateTimeFormatter fmt =
230230
DateTimeFormatter.ofPattern(
231-
&quot;yyyy-MM-dd&quot;);
231+
&quot;uuuu-MM-dd&quot;);
232232
String formatted =
233233
LocalDate.now().format(fmt);
234234
// Thread-safe, immutable</pre>

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,7 @@ <h3>Date formatting</h3>
25242524
<span class="mini-label">Modern</span>
25252525
<span class="code-text">DateTimeFormatter fmt =
25262526
DateTimeFormatter.ofPattern(
2527-
&quot;yyyy-MM-dd&quot;);
2527+
&quot;uuuu-MM-dd&quot;);
25282528
String formatted =
25292529
LocalDate.now().format(fmt);
25302530
// Thread-safe, immutable</span>

java-time-basics.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ <h3>Date formatting</h3>
294294
<div class="mini-label">Java 8+</div>
295295
<pre class="code-text">DateTimeFormatter fmt =
296296
DateTimeFormatter.ofPattern(
297-
&quot;yyyy-MM-dd&quot;);
297+
&quot;uuuu-MM-dd&quot;);
298298
String formatted =
299299
LocalDate.now().format(fmt);
300300
// Thread-safe, immutable</pre>

multiline-json-sql.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ <h1>Multiline JSON/SQL/HTML</h1>
140140
SELECT u.name, u.email
141141
FROM users u
142142
WHERE u.active = true
143-
ORDER BY u.name
144-
&quot;&quot;&quot;;</pre>
143+
ORDER BY u.name&quot;&quot;&quot;;</pre>
145144
</div>
146145
</div>
147146
</div>

text-blocks-for-multiline-strings.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ <h1>Text blocks for multiline strings</h1>
139139
{
140140
&quot;name&quot;: &quot;Duke&quot;,
141141
&quot;age&quot;: 30
142-
}
143-
&quot;&quot;&quot;;</pre>
142+
}&quot;&quot;&quot;;</pre>
144143
</div>
145144
</div>
146145
</div>

0 commit comments

Comments
 (0)