1
0
forked from test/crm

fix: added utils to get format & formatted date

This commit is contained in:
Shariq Ansari 2024-12-02 12:41:45 +05:30
parent 0cdbf98ca4
commit d991eb52ef

View File

@ -3,7 +3,7 @@ import TaskPriorityIcon from '@/components/Icons/TaskPriorityIcon.vue'
import { usersStore } from '@/stores/users'
import { gemoji } from 'gemoji'
import { useTimeAgo } from '@vueuse/core'
import { toast, convertToUserTimezone } from 'frappe-ui'
import { toast, convertToUserTimezone, luxonDate } from 'frappe-ui'
import { h } from 'vue'
export function createToast(options) {
@ -38,10 +38,34 @@ export function formatTime(seconds) {
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)
}
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) {
return useTimeAgo(date).value
}