Skip to content

Commit 1ecc243

Browse files
[photos][web] Match mobile date formatting for comments (#8626)
2 parents e39806c + bfaf073 commit 1ecc243

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

web/packages/base/locales/en-US/translation.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@
155155
"commented_on_a_video": "Commented on a video",
156156
"replied_to_a_comment": "Replied to a comment",
157157
"liked_a_comment": "Liked a comment",
158+
"just_now": "just now",
159+
"minutes_ago": "{{count}}m ago",
160+
"hours_ago": "{{count}}h ago",
161+
"days_ago": "{{count}}d ago",
158162
"like_anonymously": "Like anonymously",
159163
"join_album_and_like": "Join album and like",
160164
"keep_it_private": "Or keep it just between you and the memory.",

web/packages/gallery/components/viewer/CommentsSidebar.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
deleteReaction,
4242
} from "ente-new/photos/services/reaction";
4343
import { type UnifiedReaction } from "ente-new/photos/services/social";
44-
import { t } from "i18next";
44+
import i18n, { t } from "i18next";
4545
import React, {
4646
useCallback,
4747
useEffect,
@@ -180,14 +180,31 @@ interface CollectionInfo {
180180
const formatTimeAgo = (timestampMicros: number): string => {
181181
// Server timestamps are in microseconds, convert to milliseconds
182182
const timestampMs = Math.floor(timestampMicros / 1000);
183-
const diff = Date.now() - timestampMs;
183+
const now = Date.now();
184+
const diff = now - timestampMs;
184185
const minutes = Math.floor(diff / 60000);
185-
if (minutes < 1) return "now";
186-
if (minutes < 60) return `${minutes}m ago`;
186+
if (minutes < 1) return t("just_now");
187+
if (minutes < 60) return t("minutes_ago", { count: minutes });
187188
const hours = Math.floor(minutes / 60);
188-
if (hours < 24) return `${hours}h ago`;
189+
if (hours < 24) return t("hours_ago", { count: hours });
189190
const days = Math.floor(hours / 24);
190-
return `${days}d ago`;
191+
if (days < 7) return t("days_ago", { count: days });
192+
193+
// For 7+ days, show actual date using locale-aware formatting
194+
const date = new Date(timestampMs);
195+
const currentYear = new Date(now).getFullYear();
196+
const locale = i18n.language;
197+
if (date.getFullYear() === currentYear) {
198+
return date.toLocaleDateString(locale, {
199+
month: "short",
200+
day: "numeric",
201+
});
202+
}
203+
return date.toLocaleDateString(locale, {
204+
month: "short",
205+
day: "numeric",
206+
year: "numeric",
207+
});
191208
};
192209

193210
const getParentComment = (

0 commit comments

Comments
 (0)