add convert date/time to api in mixin
This commit is contained in:
parent
dbff789a0b
commit
920ca8e13b
1 changed files with 17 additions and 0 deletions
|
|
@ -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");
|
||||
export const useCounterMixin = defineStore("mixin", () => {
|
||||
|
|
@ -1172,6 +1173,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,
|
||||
|
|
@ -1212,5 +1227,7 @@ export const useCounterMixin = defineStore("mixin", () => {
|
|||
findPosMasterNo,
|
||||
onSearchDataTable,
|
||||
formatDatePosition,
|
||||
convertDateToAPI,
|
||||
convertDatetimeToAPI,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue