diff --git a/src/stores/mixin.ts b/src/stores/mixin.ts index 42e969e6..f40719f7 100644 --- a/src/stores/mixin.ts +++ b/src/stores/mixin.ts @@ -3,6 +3,7 @@ import "moment/dist/locale/th"; import moment from "moment"; import CustomComponent from "@/components/CustomDialog.vue"; import { Loading, QSpinnerCube } from "quasar"; +import { format, utcToZonedTime } from "date-fns-tz"; moment.locale("th"); @@ -1078,6 +1079,20 @@ export const useCounterMixin = defineStore("mixin", () => { }); } + // กรณีมีเฉพาะ 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 { calAge, date2Thai, @@ -1121,5 +1136,8 @@ export const useCounterMixin = defineStore("mixin", () => { findPosMasterNoOld, onSearchDataTable, + + convertDateToAPI, + convertDatetimeToAPI, }; });