add convert date/time to api in mixin
This commit is contained in:
parent
3c0a4fe69e
commit
619f93ccd2
1 changed files with 17 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
|
||||||
import CustomComponent from '@/components/CustomDialog.vue'
|
import CustomComponent from '@/components/CustomDialog.vue'
|
||||||
import { Loading, QSpinnerCube } from 'quasar'
|
import { Loading, QSpinnerCube } from 'quasar'
|
||||||
import { logout } from '@/plugins/auth'
|
import { logout } from '@/plugins/auth'
|
||||||
|
import { format, utcToZonedTime } from 'date-fns-tz'
|
||||||
|
|
||||||
export const useCounterMixin = defineStore('mixin', () => {
|
export const useCounterMixin = defineStore('mixin', () => {
|
||||||
function date2Thai(srcDate: Date, isFullMonth = false, isTime = false) {
|
function date2Thai(srcDate: Date, isFullMonth = false, isTime = false) {
|
||||||
|
|
@ -344,6 +345,20 @@ export const useCounterMixin = defineStore('mixin', () => {
|
||||||
return dstMonth + ' ' + dstYear
|
return dstMonth + ' ' + dstYear
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// กรณีมีเฉพาะ date
|
||||||
|
function convertDateToAPI(date: Date | null) {
|
||||||
|
return date
|
||||||
|
? format(utcToZonedTime(date, 'Asia/Bangkok'), 'yyyy-MM-dd')
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
|
||||||
|
// กรณี datetime
|
||||||
|
function convertDatetimeToAPI(date: Date | null) {
|
||||||
|
return date
|
||||||
|
? format(utcToZonedTime(date, 'Asia/Bangkok'), 'yyyy-MM-dd HH:mm:ss')
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
date2Thai,
|
date2Thai,
|
||||||
monthYear2Thai,
|
monthYear2Thai,
|
||||||
|
|
@ -355,5 +370,7 @@ export const useCounterMixin = defineStore('mixin', () => {
|
||||||
success,
|
success,
|
||||||
notify,
|
notify,
|
||||||
dialogRemove,
|
dialogRemove,
|
||||||
|
convertDateToAPI,
|
||||||
|
convertDatetimeToAPI,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue