Browse Source

feat(sdk): add timeAgo

pull/6870/head
աɨռɢӄաօռɢ 1 year ago
parent
commit
399b4c1c54
  1. 10
      packages/nocodb-sdk/src/lib/dateTimeHelper.ts

10
packages/nocodb-sdk/src/lib/dateTimeHelper.ts

@ -109,3 +109,13 @@ export const handleTZ = (val: any) => {
export function validateDateFormat(v: string) {
return dateFormats.includes(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();
};

Loading…
Cancel
Save