Skip to content

Commit 3f11970

Browse files
Optimize timestamp rendering to avoid redundant Date object creation
Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent d7b1082 commit 3f11970

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

examples/browser-demo/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,11 @@ <h2>🖥️ Console Output</h2>
475475
${task.title}
476476
</div>
477477
<div class="task-meta">
478-
ID: ${task.id} | Created: ${
479-
task.created_at && !isNaN(new Date(task.created_at).getTime())
480-
? new Date(task.created_at).toLocaleString()
481-
: 'Unknown'
482-
}
478+
ID: ${task.id} | Created: ${(() => {
479+
if (!task.created_at) return 'Unknown';
480+
const date = new Date(task.created_at);
481+
return !isNaN(date.getTime()) ? date.toLocaleString() : 'Unknown';
482+
})()}
483483
</div>
484484
</div>
485485
<div class="task-actions">

examples/browser-localstorage-demo/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,11 @@ <h2>🖥️ Console Output</h2>
314314
<div>
315315
<strong>${note.content}</strong>
316316
<div style="font-size: 0.85em; color: #666; margin-top: 5px;">
317-
Created: ${
318-
note.created_at && !isNaN(new Date(note.created_at).getTime())
319-
? new Date(note.created_at).toLocaleString()
320-
: 'Unknown'
321-
}
317+
Created: ${(() => {
318+
if (!note.created_at) return 'Unknown';
319+
const date = new Date(note.created_at);
320+
return !isNaN(date.getTime()) ? date.toLocaleString() : 'Unknown';
321+
})()}
322322
</div>
323323
</div>
324324
<button class="danger" onclick="deleteNote('${note.id}')">🗑</button>

0 commit comments

Comments
 (0)