@@ -27,6 +27,7 @@ import {
27
27
import expressWebsockets from "express-ws" ;
28
28
import ical from "node-ical" ;
29
29
import fs from "node:fs" ;
30
+ import { formatDistanceToNow } from "date-fns" ;
30
31
31
32
// Prepare Markdown renderer to force links to always target="_blank"
32
33
const renderer = {
@@ -1383,54 +1384,12 @@ const getTodayDateForHubVisitsAPI = () => {
1383
1384
const MIN = 1000 * 60 ;
1384
1385
const howManyMinutesAgo = ( date ) => {
1385
1386
if ( ! date ) return null ;
1386
- const millisNow = Date . now ( ) ;
1387
- const millisThen = date . getTime ( ) ;
1388
- const difference = millisNow - millisThen ;
1389
- return difference < 0
1390
- ? "in the future?" // ???
1391
- : difference < 2 * MIN
1392
- ? "just now"
1393
- : difference < 5 * MIN
1394
- ? "a few minutes ago"
1395
- : difference < 10 * MIN
1396
- ? "five-ish minutes ago"
1397
- : difference < 20 * MIN
1398
- ? "15 minutes ago"
1399
- : difference < 30 * MIN
1400
- ? "recently"
1401
- : difference < 45 * MIN
1402
- ? "a half hour ago"
1403
- : difference < 60 * MIN
1404
- ? "45 min ago"
1405
- : difference < 80 * MIN
1406
- ? "over an hour ago"
1407
- : "a while ago" ;
1387
+ return formatDistanceToNow ( date , { addSuffix : true } ) ;
1408
1388
} ;
1409
1389
1410
1390
const howLongInTheFuture = ( date ) => {
1411
1391
if ( ! date ) return null ;
1412
- const millisNow = Date . now ( ) ;
1413
- const millisThen = date . getTime ( ) ;
1414
- const difference = millisThen - millisNow ;
1415
- return difference < 0
1416
- ? "in the past?" // ???
1417
- : difference < 2 * MIN
1418
- ? "now"
1419
- : difference < 5 * MIN
1420
- ? "in a few minutes"
1421
- : difference < 10 * MIN
1422
- ? "in five-ish minutes"
1423
- : difference < 20 * MIN
1424
- ? "in 15 minutes"
1425
- : difference < 30 * MIN
1426
- ? "in 20 minutes"
1427
- : difference < 45 * MIN
1428
- ? "in a half hour"
1429
- : difference < 60 * MIN
1430
- ? "in 45 min"
1431
- : difference < 80 * MIN
1432
- ? "in just over an hour"
1433
- : "in quite a while" ;
1392
+ return formatDistanceToNow ( date , { addSuffix : true } ) ;
1434
1393
} ;
1435
1394
1436
1395
const countPhrase = ( count ) => {
0 commit comments