mirror of
https://github.com/nocodb/nocodb.git
synced 2026-05-04 01:57:10 +00:00
* feat: notifications wip * feat: wip * feat: longpoll and notifications.controller.ts * feat: longpoll and notifications.controller.ts * feat: enable email notifications * fix: notification styles and list * fix: update swagger feat: connect poller to frontend * fix: minor ui corrections * feat: move notifications to ee feat: scroll to commentId fix: polling fail on network error fix: unreadcount not updating fix: add workspace to comment mention event * fix: pubsub for notifications * fix: warning maxListeners * fix: update ui * fix: minor fixes * chore: move pub-sub to redis folder * fix: update ui and schema feat: optimistic comment update and create * fix: row empty during inital load causing row not loading * fix: build * fix: some updated * fix: minor ui corrections * fix: manage local state manually for interactivity * fix: remove prev notifcation data * fix: review comments * fix: code rabbit comments * fix: code rabbit comments * feat: delete notifications * fix: code rabbit comments * fix: row RowMeta manipulation fix: overflow notifications * fix: invalid offset * fix: updated widths * fix: tests * fix: playwright * feat: resolved by comments * feat: update layout * fix: wait 5 seconds before polling start, after polling starts, reload the notifications * fix: bug fixes * fix: disable long polling for playwright * fix: update migration * fix: lint * fix: code rabbit comments * fix: resolve tooltip * feat: resolve ee * fix: build failing * fix: review comments * fix: dependency synx * fix: update notification style
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
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: string) => {
|
|
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
|
|
const diff = dayjs().diff(date)
|
|
|
|
const seconds = Math.floor(diff / 1000)
|
|
const minutes = Math.floor(seconds / 60)
|
|
const hours = Math.floor(minutes / 60)
|
|
const days = Math.floor(hours / 24)
|
|
const months = Math.floor(days / 30)
|
|
const years = Math.floor(days / 365)
|
|
|
|
if (seconds < 60) {
|
|
if (seconds < 0) return '1s ago'
|
|
return `${seconds}s ago`
|
|
}
|
|
if (minutes < 60) {
|
|
return `${minutes}m ago`
|
|
}
|
|
if (hours < 24) {
|
|
return `${hours}h ago`
|
|
}
|
|
if (days < 30) {
|
|
return `${days}d ago`
|
|
}
|
|
if (months < 12) {
|
|
return `${months}mo ago`
|
|
}
|
|
return `${years}y ago`
|
|
}
|