Buckets:
| type TimeKey = | |
| | "common.time.justNow" | |
| | "common.time.minutesAgo.short" | |
| | "common.time.hoursAgo.short" | |
| | "common.time.daysAgo.short" | |
| type Translate = (key: TimeKey, params?: Record<string, string | number>) => string | |
| export function getRelativeTime(dateString: string, t: Translate): string { | |
| const date = new Date(dateString) | |
| const now = new Date() | |
| const diffMs = now.getTime() - date.getTime() | |
| const diffSeconds = Math.floor(diffMs / 1000) | |
| const diffMinutes = Math.floor(diffSeconds / 60) | |
| const diffHours = Math.floor(diffMinutes / 60) | |
| const diffDays = Math.floor(diffHours / 24) | |
| if (diffSeconds < 60) return t("common.time.justNow") | |
| if (diffMinutes < 60) return t("common.time.minutesAgo.short", { count: diffMinutes }) | |
| if (diffHours < 24) return t("common.time.hoursAgo.short", { count: diffHours }) | |
| return t("common.time.daysAgo.short", { count: diffDays }) | |
| } | |
Xet Storage Details
- Size:
- 898 Bytes
- Xet hash:
- 2c93ebef94237cf874cd8024efbd0063fc2781bedf2e1503f3ac3733bbe460c5
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.