import dayjs from 'dayjs' import { dateFormats, timeFormats } from 'nocodb-sdk' export function parseStringDateTime( v: string, dateTimeFormat: string = `${dateFormats[0]} ${timeFormats[0]}`, toLocal: boolean = true, ) { const dayjsObj = toLocal ? dayjs(v).local() : dayjs(v) if (dayjsObj.isValid()) { v = dayjsObj.format(dateTimeFormat) } else { v = toLocal ? dayjs(v, dateTimeFormat).local().format(dateTimeFormat) : dayjs(v, dateTimeFormat).format(dateTimeFormat) } return v } export const timeAgo = (date: any) => { if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(date)) { // if there is no timezone info, consider as UTC // e.g. 2023-01-01 08:00:00 (MySQL) date += '+00:00' } // show in local time return dayjs(date).fromNow() }