Merge pull request #870 from frappe/main-hotfix
This commit is contained in:
commit
8f1249a4c9
@ -2,9 +2,8 @@ import TaskStatusIcon from '@/components/Icons/TaskStatusIcon.vue'
|
||||
import TaskPriorityIcon from '@/components/Icons/TaskPriorityIcon.vue'
|
||||
import { usersStore } from '@/stores/users'
|
||||
import { gemoji } from 'gemoji'
|
||||
import { useTimeAgo } from '@vueuse/core'
|
||||
import { getMeta } from '@/stores/meta'
|
||||
import { toast, dayjsLocal, dayjs } from 'frappe-ui'
|
||||
import { toast, dayjsLocal, dayjs, getConfig } from 'frappe-ui'
|
||||
import { h } from 'vue'
|
||||
|
||||
export function formatTime(seconds) {
|
||||
@ -65,7 +64,85 @@ export function getFormat(
|
||||
}
|
||||
|
||||
export function timeAgo(date) {
|
||||
return useTimeAgo(date).value
|
||||
return prettyDate(date)
|
||||
}
|
||||
|
||||
function getBrowserTimezone() {
|
||||
return Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||
}
|
||||
|
||||
export function prettyDate(date, mini = false) {
|
||||
if (!date) return ''
|
||||
|
||||
let systemTimezone = getConfig('systemTimezone')
|
||||
let localTimezone = getConfig('localTimezone') || getBrowserTimezone()
|
||||
|
||||
if (typeof date == 'string') {
|
||||
date = dayjsLocal(date)
|
||||
}
|
||||
|
||||
let nowDatetime = dayjs().tz(localTimezone || systemTimezone)
|
||||
let diff = nowDatetime.diff(date, 'seconds')
|
||||
|
||||
let dayDiff = Math.floor(diff / 86400)
|
||||
|
||||
if (isNaN(dayDiff) || dayDiff < 0) return ''
|
||||
|
||||
if (mini) {
|
||||
// Return short format of time difference
|
||||
if (dayDiff == 0) {
|
||||
if (diff < 60) {
|
||||
return __('now')
|
||||
} else if (diff < 3600) {
|
||||
return __('{0} m', [Math.floor(diff / 60)])
|
||||
} else if (diff < 86400) {
|
||||
return __('{0} h', [Math.floor(diff / 3600)])
|
||||
}
|
||||
} else {
|
||||
if (dayDiff < 7) {
|
||||
return __('{0} d', [dayDiff])
|
||||
} else if (dayDiff < 31) {
|
||||
return __('{0} w', [Math.floor(dayDiff / 7)])
|
||||
} else if (dayDiff < 365) {
|
||||
return __('{0} M', [Math.floor(dayDiff / 30)])
|
||||
} else {
|
||||
return __('{0} y', [Math.floor(dayDiff / 365)])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Return long format of time difference
|
||||
if (dayDiff == 0) {
|
||||
if (diff < 60) {
|
||||
return __('just now')
|
||||
} else if (diff < 120) {
|
||||
return __('1 minute ago')
|
||||
} else if (diff < 3600) {
|
||||
return __('{0} minutes ago', [Math.floor(diff / 60)])
|
||||
} else if (diff < 7200) {
|
||||
return __('1 hour ago')
|
||||
} else if (diff < 86400) {
|
||||
return __('{0} hours ago', [Math.floor(diff / 3600)])
|
||||
}
|
||||
} else {
|
||||
if (dayDiff == 1) {
|
||||
return __('yesterday')
|
||||
} else if (dayDiff < 7) {
|
||||
return __('{0} days ago', [dayDiff])
|
||||
} else if (dayDiff < 14) {
|
||||
return __('1 week ago')
|
||||
} else if (dayDiff < 31) {
|
||||
return __('{0} weeks ago', [Math.floor(dayDiff / 7)])
|
||||
} else if (dayDiff < 62) {
|
||||
return __('1 month ago')
|
||||
} else if (dayDiff < 365) {
|
||||
return __('{0} months ago', [Math.floor(dayDiff / 30)])
|
||||
} else if (dayDiff < 730) {
|
||||
return __('1 year ago')
|
||||
} else {
|
||||
return __('{0} years ago', [Math.floor(dayDiff / 365)])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function taskStatusOptions(action, data) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user