Browse Source

fix(nc-gui): timeAgo logic

pull/5505/head
Wing-Kam Wong 2 years 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' import dayjs from 'dayjs'
// show in local time
export const timeAgo = (date: any) => { export const timeAgo = (date: any) => {
// handle Z and +00:00 if (/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(date)) {
if (date.slice(-1) === 'Z' || date.slice(-6) === '+00:00') { // if there is no timezone info, consider as UTC
return dayjs(date).fromNow() // 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 = [ export const dateFormats = [

Loading…
Cancel
Save