update note display

This commit is contained in:
2023-04-29 19:10:25 +02:00
parent 4cc7c01365
commit 96e3bed77d
11 changed files with 250 additions and 61 deletions

26
src/utils/helpers.ts Normal file
View File

@@ -0,0 +1,26 @@
import { formatDistance, format, isToday } from 'date-fns'
export const formatDate = (date: Date | number): string => {
const dateToFormat = ['number', 'string'].includes(typeof date)
? new Date(date)
: date
const dateDistanceInWords = formatDistance(dateToFormat, new Date()) + ' ago'
return isToday(date)
? dateDistanceInWords
: format(date, 'D MMMM [at] HH:mm ')
}
export const getAllMatches = (
regex: RegExp,
input: string
): RegExpExecArray[] => {
const matches = []
let m
do {
m = regex.exec(input)
// console.log(m)
if (m) matches.push(m)
} while (m)
return matches
}