add function formatted date/time to API in mixin
This commit is contained in:
parent
197b621436
commit
126fbdbed1
2 changed files with 20 additions and 7 deletions
|
|
@ -1,7 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, reactive, watch, onMounted } from "vue";
|
||||
import { useQuasar } from "quasar";
|
||||
import { format, utcToZonedTime } from "date-fns-tz";
|
||||
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
|
|
@ -25,6 +24,7 @@ const {
|
|||
showLoader,
|
||||
hideLoader,
|
||||
success,
|
||||
convertDateToAPI,
|
||||
} = mixin;
|
||||
|
||||
const emit = defineEmits(["update:change-page"]);
|
||||
|
|
@ -113,12 +113,7 @@ function onSubmit() {
|
|||
|
||||
/** Function เปลี่ยนรอบเวลา*/
|
||||
async function changeRound() {
|
||||
const formattedDateForAPI = await (formData.effectiveDate
|
||||
? format(
|
||||
utcToZonedTime(formData.effectiveDate, "Asia/Bangkok"),
|
||||
"yyyy-MM-dd"
|
||||
)
|
||||
: null);
|
||||
const formattedDateForAPI = await convertDateToAPI(formData.effectiveDate);
|
||||
|
||||
showLoader();
|
||||
await http
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue