แก้date2Thaiใน Mixinเป็นmoment
This commit is contained in:
parent
1055b026f5
commit
a14eca2d5b
1 changed files with 12 additions and 69 deletions
|
|
@ -1,8 +1,11 @@
|
|||
import { defineStore } from "pinia";
|
||||
import "moment/dist/locale/th";
|
||||
import moment from "moment";
|
||||
import CustomComponent from "@/components/CustomDialog.vue";
|
||||
import { Loading, QSpinnerCube } from "quasar";
|
||||
|
||||
moment.locale("th");
|
||||
|
||||
export const useCounterMixin = defineStore("mixin", () => {
|
||||
/**
|
||||
* ฟังก์ชันกลาง
|
||||
|
|
@ -70,78 +73,18 @@ export const useCounterMixin = defineStore("mixin", () => {
|
|||
};
|
||||
|
||||
function date2Thai(
|
||||
srcDate: Date,
|
||||
srcDate: Date | null,
|
||||
isFullMonth: boolean = false,
|
||||
isTime: boolean = false
|
||||
) {
|
||||
if (srcDate == null) {
|
||||
return null;
|
||||
`
|
||||
`;
|
||||
}
|
||||
const date = new Date(srcDate);
|
||||
const isValidDate = Boolean(+date);
|
||||
if (!isValidDate) return srcDate.toString();
|
||||
if (isValidDate && date.getFullYear() < 1000) return srcDate.toString();
|
||||
const fullMonthThai = [
|
||||
"มกราคม",
|
||||
"กุมภาพันธ์",
|
||||
"มีนาคม",
|
||||
"เมษายน",
|
||||
"พฤษภาคม",
|
||||
"มิถุนายน",
|
||||
"กรกฎาคม",
|
||||
"สิงหาคม",
|
||||
"กันยายน",
|
||||
"ตุลาคม",
|
||||
"พฤศจิกายน",
|
||||
"ธันวาคม",
|
||||
];
|
||||
const abbrMonthThai = [
|
||||
"ม.ค.",
|
||||
"ก.พ.",
|
||||
"มี.ค.",
|
||||
"เม.ย.",
|
||||
"พ.ค.",
|
||||
"มิ.ย.",
|
||||
"ก.ค.",
|
||||
"ส.ค.",
|
||||
"ก.ย.",
|
||||
"ต.ค.",
|
||||
"พ.ย.",
|
||||
"ธ.ค.",
|
||||
];
|
||||
let dstYear = 0;
|
||||
if (date.getFullYear() > 2500) {
|
||||
dstYear = date.getFullYear();
|
||||
} else {
|
||||
dstYear = date.getFullYear() + 543;
|
||||
}
|
||||
let dstMonth = "";
|
||||
if (isFullMonth) {
|
||||
dstMonth = fullMonthThai[date.getMonth()];
|
||||
} else {
|
||||
dstMonth = abbrMonthThai[date.getMonth()];
|
||||
}
|
||||
let dstTime = "";
|
||||
if (isTime) {
|
||||
// const H = date.getHours().toString().padStart(2, "0");
|
||||
// const M = date.getMinutes().toString().padStart(2, "0");
|
||||
const H = date.getHours().toString().padStart(2);
|
||||
const M = date.getMinutes().toString().padStart(2);
|
||||
// const S = date.getSeconds().toString().padStart(2, "0")
|
||||
// dstTime = " " + H + ":" + M + ":" + S + " น."
|
||||
dstTime = " " + H + ":" + M + " น.";
|
||||
}
|
||||
return (
|
||||
// date.getDate().toString().padStart(2, "0") +
|
||||
date.getDate().toString().padStart(2) +
|
||||
" " +
|
||||
dstMonth +
|
||||
" " +
|
||||
dstYear +
|
||||
dstTime
|
||||
);
|
||||
if (srcDate == null) return null;
|
||||
const dateMoment = moment(srcDate);
|
||||
const day = dateMoment.format("DD");
|
||||
const month = dateMoment.format(isFullMonth ? "MMMM" : "MMM");
|
||||
const year = +dateMoment.format("YYYY") + 543;
|
||||
return `${day} ${month} ${year}${
|
||||
isTime ? dateMoment.format(" hh:mm น.") : ""
|
||||
}`;
|
||||
}
|
||||
|
||||
function dateMonth2Thai(srcDate: Date, isFullMonth = false, isTime = false) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue