Skip to content

Commit 3fa3d81

Browse files
Copilotbrunoborges
andcommitted
Fix multiline strings and date formatting patterns
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent c2bc4be commit 3fa3d81

File tree

8 files changed

+16
-18
lines changed

8 files changed

+16
-18
lines changed

data/snippets.json

Lines changed: 4 additions & 4 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": [
@@ -2424,8 +2424,8 @@
24242424
"modernLabel": "Java 8+",
24252425
"oldApproach": "SimpleDateFormat",
24262426
"modernApproach": "DateTimeFormatter",
2427-
"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",
2427+
"oldCode": "// Not thread-safe!\nSimpleDateFormat sdf =\n new SimpleDateFormat(\"uuuu-MM-dd\");\nString formatted = sdf.format(date);\n// Must synchronize for concurrent use",
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ <h1>Date formatting</h1>
125125
<div class="compare-code">
126126
<pre class="code-text">// Not thread-safe!
127127
SimpleDateFormat sdf =
128-
new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
128+
new SimpleDateFormat(&quot;uuuu-MM-dd&quot;);
129129
String formatted = sdf.format(date);
130130
// Must synchronize for concurrent use</pre>
131131
</div>
@@ -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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ <h3>Date formatting</h3>
254254
<div class="mini-label">Pre-Java 8</div>
255255
<pre class="code-text">// Not thread-safe!
256256
SimpleDateFormat sdf =
257-
new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
257+
new SimpleDateFormat(&quot;uuuu-MM-dd&quot;);
258258
String formatted = sdf.format(date);
259259
// Must synchronize for concurrent use</pre>
260260
</div>
261261
<div class="card-code-layer modern-layer">
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ <h3>Date formatting</h3>
220220
<div class="mini-label">Pre-Java 8</div>
221221
<pre class="code-text">// Not thread-safe!
222222
SimpleDateFormat sdf =
223-
new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
223+
new SimpleDateFormat(&quot;uuuu-MM-dd&quot;);
224224
String formatted = sdf.format(date);
225225
// Must synchronize for concurrent use</pre>
226226
</div>
227227
<div class="card-code-layer modern-layer">
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,15 +2516,15 @@ <h3>Date formatting</h3>
25162516
<span class="mini-label">Old</span>
25172517
<span class="code-text">// Not thread-safe!
25182518
SimpleDateFormat sdf =
2519-
new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
2519+
new SimpleDateFormat(&quot;uuuu-MM-dd&quot;);
25202520
String formatted = sdf.format(date);
25212521
// Must synchronize for concurrent use</span>
25222522
</div>
25232523
<div class="card-code-layer modern-layer">
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ <h3>Date formatting</h3>
286286
<div class="mini-label">Pre-Java 8</div>
287287
<pre class="code-text">// Not thread-safe!
288288
SimpleDateFormat sdf =
289-
new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
289+
new SimpleDateFormat(&quot;uuuu-MM-dd&quot;);
290290
String formatted = sdf.format(date);
291291
// Must synchronize for concurrent use</pre>
292292
</div>
293293
<div class="card-code-layer modern-layer">
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)