Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | 27x 27x 27x 29x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 230x 230x 230x 230x 230x 1x 229x 228x 227x 227x 226x 1x 225x 224x 1x 223x 222x 1x 221x 220x 1x 219x 28x 192x 192x 192x 192x 192x 192x 192x 192x 192x 192x 192x 192x 192x 192x 192x 192x 192x 192x | import { TFunction } from "i18next"; export const minuteMillis = 60000; export const twoMinuteMillis = 120000; export const quarterHourMillis = 900000; export const hourMillis = 3600000; export const twoHourMillis = 7200000; export const dayMillis = 86400000; export const twoDayMillis = 172800000; export const weekMillis = 604800000; export const twoWeekMillis = 1209600000; export const monthMillis = weekMillis * 4; export const twoMonthMillis = weekMillis * 8; export const yearMillis = 31557600000; export const twoYearMillis = 31557600000 * 2; export const lessThanHour = "Less than an hour ago"; export interface FuzzySpec { millis: number; text: string; } /** * @deprecated Use `timeAgoI18n` instead. */ export function timeAgo(input: Date | string, fuzzy?: FuzzySpec) { Iif (input === undefined) return ""; const date = new Date(input); const diffMillis = Date.now() - date.getTime(); if (fuzzy && diffMillis < fuzzy.millis) { // if fuzzyMillis and fuzzyText are both set, then for times less than fuzzyMillis, we return fuzzyText return fuzzy.text; } if (diffMillis <= minuteMillis) return "< 1 minute ago"; if (diffMillis <= twoMinuteMillis) return "1 minute ago"; Iif (diffMillis < hourMillis) return "" + (diffMillis / minuteMillis).toFixed() + " minutes ago"; if (diffMillis < twoHourMillis) return "1 hour ago"; if (diffMillis < dayMillis) return "" + (diffMillis / hourMillis).toFixed() + " hours ago"; if (diffMillis < twoDayMillis) return "1 day ago"; if (diffMillis < weekMillis) return "" + (diffMillis / dayMillis).toFixed() + " days ago"; if (diffMillis < twoWeekMillis) return "1 week ago"; if (diffMillis < monthMillis) return "" + (diffMillis / weekMillis).toFixed() + " weeks ago"; if (diffMillis < twoMonthMillis) return "1 month ago"; if (diffMillis < yearMillis) return "" + (diffMillis / monthMillis).toFixed() + " months ago"; if (diffMillis < twoYearMillis) return "1 year ago"; return "" + (diffMillis / yearMillis).toFixed() + " years ago"; } export interface FuzzySpecT { millis: number; translationKey: Parameters<TFunction<"global", undefined>>[0]; } export function timeAgoI18n({ input, t, fuzzy = undefined, }: { input: Date | string; t: TFunction<"global", undefined>; fuzzy?: FuzzySpecT; }) { Iif (input === undefined) return ""; const date = new Date(input); const diffMillis = Date.now() - date.getTime(); Iif (fuzzy && diffMillis < fuzzy.millis) { // if fuzzyMillis and fuzzyText are both set, then for times less than fuzzyMillis, we return fuzzyText return t(fuzzy.translationKey) as string; } Iif (diffMillis < minuteMillis) return t("relative_time.less_than_a_minute_ago"); Iif (diffMillis < twoMinuteMillis) return t("relative_time.one_minute_ago"); Iif (diffMillis < hourMillis) return t("relative_time.x_minutes_ago", { date: (diffMillis / minuteMillis).toFixed(), }); Iif (diffMillis < twoHourMillis) return t("relative_time.one_hour_ago"); Iif (diffMillis < dayMillis) return t("relative_time.x_hours_ago", { date: (diffMillis / hourMillis).toFixed(), }); Iif (diffMillis < twoDayMillis) return t("relative_time.one_day_ago"); Iif (diffMillis < weekMillis) return t("relative_time.x_days_ago", { date: (diffMillis / dayMillis).toFixed(), }); Iif (diffMillis < twoWeekMillis) return t("relative_time.one_week_ago"); Iif (diffMillis < monthMillis) return t("relative_time.x_weeks_ago", { date: (diffMillis / weekMillis).toFixed(), }); Iif (diffMillis < twoMonthMillis) return t("relative_time.one_month_ago"); Iif (diffMillis < yearMillis) return t("relative_time.x_months_ago", { date: (diffMillis / monthMillis).toFixed(), }); Iif (diffMillis < twoYearMillis) return t("relative_time.one_year_ago"); return t("relative_time.x_years_ago", { date: (diffMillis / yearMillis).toFixed(), }); } |