History

Pull uncommitted work: relative time formatting tweaks (worktree 2d307dad)

Theo Browne committed 4 months ago

Commit fab05c31 parent 6f5dd373 files · +6 −5Browse files

Unified · Split

3 files
  1. apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx +1 −1
  2. apps/mobile/src/features/home/HomeScreen.tsx +1 −1
  3. apps/mobile/src/lib/time.ts +4 −3
apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx+1−1
@@ -272,7 +272,7 @@ function ArchivedThreadRow(props: { · 271 unmodified lines
272 </Text>272 </Text>
273 <Text273 <Text
274 className="text-xs text-foreground-tertiary"274 className="text-xs text-foreground-tertiary"
275 style={{ fontVariant: ["tabular-nums"] }}275 style={{ fontVariant: ["tabular-nums"], minWidth: 30, textAlign: "right" }}
276 >276 >
277 {timestamp}277 {timestamp}
278 </Text>278 </Text>
apps/mobile/src/features/home/HomeScreen.tsx+1−1
@@ -370,7 +370,7 @@ function ThreadRow(props: { · 369 unmodified lines
370 </View>370 </View>
371 <Text371 <Text
372 className="text-xs text-foreground-tertiary"372 className="text-xs text-foreground-tertiary"
373 style={{ fontVariant: ["tabular-nums"] }}373 style={{ fontVariant: ["tabular-nums"], minWidth: 30, textAlign: "right" }}
374 >374 >
375 {timestamp}375 {timestamp}
376 </Text>376 </Text>
apps/mobile/src/lib/time.ts+4−3
@@ -1,12 +1,13 @@
1export function relativeTime(input: string): string {1export function relativeTime(input: string): string {
2 const timestamp = Date.parse(input);2 const timestamp = Date.parse(input);
3 if (Number.isNaN(timestamp)) {3 if (Number.isNaN(timestamp)) {
4 return "now";4 return "<1m";
5 }5 }
6 6
7 // Anything under a minute renders as "<1m" rather than a live seconds count.
8 // The seconds ticker changed width every second and reflowed the surrounding row.
7 const deltaSeconds = Math.max(0, Math.floor((Date.now() - timestamp) / 1000));9 const deltaSeconds = Math.max(0, Math.floor((Date.now() - timestamp) / 1000));
8 if (deltaSeconds < 10) return "now";10 if (deltaSeconds < 60) return "<1m";
9 if (deltaSeconds < 60) return `${deltaSeconds}s`;
10 11
11 const deltaMinutes = Math.floor(deltaSeconds / 60);12 const deltaMinutes = Math.floor(deltaSeconds / 60);
12 if (deltaMinutes < 60) return `${deltaMinutes}m`;13 if (deltaMinutes < 60) return `${deltaMinutes}m`;