char/sorcery
static-files based git repo viewer
git clone https://git.t4t.associates/char/sorcery
c166af0
main
1import { assertEquals } from "jsr:@std/assert@1" ; 2import { commitDate , timeAgo } from "./util.ts" ; 3 4const now = new Date ( "2026-10-05T12:00:00Z" ); 5const before = ( seconds :number ) => new Date ( now . getTime () - seconds * 1000 ); 6 7Deno . test ( "timeAgo picks the largest whole unit" , () => { 8assertEquals ( timeAgo ( before ( 47 * 60 + 59 ), now ), "47 minutes ago" ); 9assertEquals ( timeAgo ( before ( 3 * 86400 + 3600 ), now ), "3 days ago" ); 10assertEquals ( timeAgo ( before ( 86400 ), now ), "yesterday" ); 11assertEquals ( timeAgo ( before ( 13 * 86400 ), now ), "last week" ); 12assertEquals ( timeAgo ( before ( 400 * 86400 ), now ), "last year" ); 13}); 14 15Deno . test ( "timeAgo reads the future as now" , () => { 16assertEquals ( timeAgo ( before ( 0 ), now ), "now" ); 17assertEquals ( timeAgo ( before ( - 90 ), now ), "now" ); 18}); 19 20Deno . test ( "commitDate is relative only while recent" , () => { 21const id = ( date :Date ) => ({ time :date . getTime () / 1000 , tz :"+0000" }); 22assertEquals ( commitDate ( id ( before ( 3 * 86400 )), now ), "3 days ago" ); 23assertEquals ( commitDate ( id ( before ( 29 * 86400 )), now ), "4 weeks ago" ); 24assertEquals ( commitDate ( id ( before ( 30 * 86400 )), now ), "2026-09-05" ); 25assertEquals ( commitDate ( id ( before ( 400 * 86400 )), now ), "2025-08-31" ); 26});