Skip to content

Instantly share code, notes, and snippets.

View justinemar's full-sized avatar
💻
Focusing

spacetime justinemar

💻
Focusing
View GitHub Profile
@justinemar
justinemar / getRelativeTimeString.ts
Created March 17, 2022 07:52 — forked from LewisJEllis/getRelativeTimeString.ts
Simplified getRelativeTimeString
// from https://twitter.com/Steve8708/status/1504131981444980739
// simplified to a function body of 10 tidy lines
// no loop needed, no 2d array of 3-tuples needed
// just 2 arrays, a findIndex call, and some indexing :)
export function getRelativeTimeString(
date: Date | number,
lang = "en"
): string {
const time = typeof date === "number" ? date : date.getTime();