From 619f93ccd2f733677b2516056b27db8bb085e8fb Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Mon, 10 Mar 2025 17:17:04 +0700 Subject: [PATCH] add convert date/time to api in mixin --- src/stores/mixin.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/stores/mixin.ts b/src/stores/mixin.ts index 8249a7f..f49ec40 100644 --- a/src/stores/mixin.ts +++ b/src/stores/mixin.ts @@ -2,6 +2,7 @@ import { defineStore } from 'pinia' import CustomComponent from '@/components/CustomDialog.vue' import { Loading, QSpinnerCube } from 'quasar' import { logout } from '@/plugins/auth' +import { format, utcToZonedTime } from 'date-fns-tz' export const useCounterMixin = defineStore('mixin', () => { function date2Thai(srcDate: Date, isFullMonth = false, isTime = false) { @@ -344,6 +345,20 @@ export const useCounterMixin = defineStore('mixin', () => { 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 { date2Thai, monthYear2Thai, @@ -355,5 +370,7 @@ export const useCounterMixin = defineStore('mixin', () => { success, notify, dialogRemove, + convertDateToAPI, + convertDatetimeToAPI, } })