fix: added utils to get format & formatted date
This commit is contained in:
parent
0cdbf98ca4
commit
d991eb52ef
@ -3,7 +3,7 @@ import TaskPriorityIcon from '@/components/Icons/TaskPriorityIcon.vue'
|
|||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
import { gemoji } from 'gemoji'
|
import { gemoji } from 'gemoji'
|
||||||
import { useTimeAgo } from '@vueuse/core'
|
import { useTimeAgo } from '@vueuse/core'
|
||||||
import { toast, convertToUserTimezone } from 'frappe-ui'
|
import { toast, convertToUserTimezone, luxonDate } from 'frappe-ui'
|
||||||
import { h } from 'vue'
|
import { h } from 'vue'
|
||||||
|
|
||||||
export function createToast(options) {
|
export function createToast(options) {
|
||||||
@ -38,10 +38,34 @@ export function formatTime(seconds) {
|
|||||||
return formattedTime.trim()
|
return formattedTime.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatDate(date, format = 'EEE, MMM d, yyyy h:mm a') {
|
export function formatDate(date, format, onlyDate = false, onlyTime = false) {
|
||||||
|
format = getFormat(date, format, onlyDate, onlyTime, false)
|
||||||
return convertToUserTimezone(date, format)
|
return convertToUserTimezone(date, format)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getFormat(
|
||||||
|
date,
|
||||||
|
format,
|
||||||
|
onlyDate = false,
|
||||||
|
onlyTime = false,
|
||||||
|
withDate = true,
|
||||||
|
) {
|
||||||
|
if (!date) return ''
|
||||||
|
let dateFormat =
|
||||||
|
window.sysdefaults.date_format.replace('mm', 'MM') || 'yyyy-MM-dd'
|
||||||
|
let timeFormat = window.sysdefaults.time_format || 'HH:mm:ss'
|
||||||
|
format = format || 'EEE, MMM d, yyyy h:mm a'
|
||||||
|
|
||||||
|
if (onlyDate) format = dateFormat
|
||||||
|
if (onlyTime) format = timeFormat
|
||||||
|
if (onlyTime && onlyDate) format = `${dateFormat} ${timeFormat}`
|
||||||
|
|
||||||
|
if (withDate) {
|
||||||
|
return luxonDate(date).toFormat(format)
|
||||||
|
}
|
||||||
|
return format
|
||||||
|
}
|
||||||
|
|
||||||
export function timeAgo(date) {
|
export function timeAgo(date) {
|
||||||
return useTimeAgo(date).value
|
return useTimeAgo(date).value
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user