add function formatted date/time to API in mixin

This commit is contained in:
Warunee Tamkoo 2025-03-10 17:07:00 +07:00
parent 197b621436
commit 126fbdbed1
2 changed files with 20 additions and 7 deletions

View file

@ -4,6 +4,7 @@ import moment from "moment";
import CustomComponent from "@/components/CustomDialog.vue";
import { Loading, QSpinnerCube } from "quasar";
import { logout } from "@/plugins/auth";
import { format, utcToZonedTime } from "date-fns-tz";
moment.locale("th");
@ -1177,6 +1178,20 @@ export const useCounterMixin = defineStore("mixin", () => {
// return `${y} ปี ${m} เดือน ${d} วัน`;
}
// กรณีมีเฉพาะ 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,
@ -1225,5 +1240,8 @@ export const useCounterMixin = defineStore("mixin", () => {
onSearchDataTable,
formatDatePosition,
formatDatePositionReport,
convertDateToAPI,
convertDatetimeToAPI,
};
});