add convert data/time to api in mixin

This commit is contained in:
Warunee Tamkoo 2025-03-10 17:23:14 +07:00
parent 6744d4d243
commit b589f98bf1

View file

@ -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,
};
});