Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'show_timestamp_after_7d' of https://github.com/benharri-forks/social-app into main

+15 -9
+7 -3
__tests__/lib/string.test.ts
··· 176 176 new Date().setMinutes(new Date().getMinutes() - 10), 177 177 new Date().setHours(new Date().getHours() - 1), 178 178 new Date().setDate(new Date().getDate() - 1), 179 + new Date().setDate(new Date().getDate() - 6), 180 + new Date().setDate(new Date().getDate() - 7), 179 181 new Date().setMonth(new Date().getMonth() - 1), 180 182 ] 181 183 const outputs = [ 182 - new Date(1671461038).toLocaleDateString(), 183 - new Date('04 Dec 1995 00:12:00 GMT').toLocaleDateString(), 184 + new Date(1671461038).toLocaleDateString('en-us', {year: 'numeric', month: 'short', day: 'numeric'}), 185 + new Date('04 Dec 1995 00:12:00 GMT').toLocaleDateString('en-us', {year: 'numeric', month: 'short', day: 'numeric'}), 184 186 '0s', 185 187 '10m', 186 188 '1h', 187 189 '1d', 188 - '1mo', 190 + '6d', 191 + new Date(new Date().setDate(new Date().getDate() - 7)).toLocaleDateString('en-us', {year: 'numeric', month: 'short', day: 'numeric'}), 192 + new Date(new Date().setMonth(new Date().getMonth() - 1)).toLocaleDateString('en-us', {year: 'numeric', month: 'short', day: 'numeric'}), 189 193 ] 190 194 191 195 it('correctly calculates how much time passed, in a string', () => {
+8 -6
src/lib/strings/time.ts
··· 1 1 const MINUTE = 60 2 2 const HOUR = MINUTE * 60 3 3 const DAY = HOUR * 24 4 - const MONTH = DAY * 28 5 - const YEAR = DAY * 365 4 + const WEEK = DAY * 7 5 + 6 6 export function ago(date: number | string | Date): string { 7 7 let ts: number 8 8 if (typeof date === 'string') { ··· 19 19 return `${Math.floor(diffSeconds / MINUTE)}m` 20 20 } else if (diffSeconds < DAY) { 21 21 return `${Math.floor(diffSeconds / HOUR)}h` 22 - } else if (diffSeconds < MONTH) { 22 + } else if (diffSeconds < WEEK) { 23 23 return `${Math.floor(diffSeconds / DAY)}d` 24 - } else if (diffSeconds < YEAR) { 25 - return `${Math.floor(diffSeconds / MONTH)}mo` 26 24 } else { 27 - return new Date(ts).toLocaleDateString() 25 + return new Date(ts).toLocaleDateString('en-us', { 26 + year: 'numeric', 27 + month: 'short', 28 + day: 'numeric', 29 + }) 28 30 } 29 31 } 30 32