Browse Source

fix(nc-gui): timeAgo logic

pull/5505/head
Wing-Kam Wong 1 year ago
parent
commit
fe3443ec72
  1. 11
      packages/nc-gui/utils/dateTimeUtils.ts

11
packages/nc-gui/utils/dateTimeUtils.ts

@ -1,12 +1,13 @@
import dayjs from 'dayjs'
// show in local time
export const timeAgo = (date: any) => {
// handle Z and +00:00
if (date.slice(-1) === 'Z' || date.slice(-6) === '+00:00') {
return dayjs(date).fromNow()
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'
}
return dayjs(date).utc(true).local().fromNow()
// show in local time
return dayjs(date).fromNow()
}
export const dateFormats = [

Loading…
Cancel
Save