mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-05-02 03:22:40 +02:00
fix: use calendar date comparison for message timestamps
The old code in app.js used elapsed-time division to determine "today" vs "yesterday", causing messages from late evening to show as "today" when viewed shortly after midnight. Now both app.js and dm.js compare calendar dates via toDateString(). Also adds "Yesterday" label support to dm.js. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2865,14 +2865,15 @@ function formatTime(timestamp) {
|
||||
return date.toLocaleDateString() + ' ' + date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
|
||||
// When viewing live messages, use relative time
|
||||
// When viewing live messages, compare calendar dates
|
||||
const now = new Date();
|
||||
const diffDays = Math.floor((now - date) / (1000 * 60 * 60 * 24));
|
||||
const yesterday = new Date(now);
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
|
||||
if (diffDays === 0) {
|
||||
if (date.toDateString() === now.toDateString()) {
|
||||
// Today - show time only
|
||||
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
} else if (diffDays === 1) {
|
||||
} else if (date.toDateString() === yesterday.toDateString()) {
|
||||
// Yesterday
|
||||
return 'Yesterday ' + date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
} else {
|
||||
|
||||
@@ -1662,10 +1662,13 @@ function formatTime(timestamp) {
|
||||
|
||||
const date = new Date(timestamp * 1000);
|
||||
const now = new Date();
|
||||
const isToday = date.toDateString() === now.toDateString();
|
||||
const yesterday = new Date(now);
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
|
||||
if (isToday) {
|
||||
if (date.toDateString() === now.toDateString()) {
|
||||
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
} else if (date.toDateString() === yesterday.toDateString()) {
|
||||
return 'Yesterday ' + date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
} else {
|
||||
return date.toLocaleDateString([], { month: 'short', day: 'numeric' }) +
|
||||
' ' + date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
|
||||
Reference in New Issue
Block a user