แก้ไขการแสดงผลการลาในส่วน

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-01-05 17:51:49 +07:00
parent b670ae3733
commit 1d624cd854
8 changed files with 233 additions and 13 deletions

View file

@ -858,6 +858,67 @@ export const useCounterMixin = defineStore("mixin", () => {
}
};
/**
*
* @param startDate format MM-DD-YYYY"
* @param endDate format MM-DD-YYYY"
* @returns 1 10 5
*/
function calculateDurationYmd(startDate: any, endDate: any) {
if (startDate && endDate) {
const start = new Date(startDate);
const end = new Date(endDate);
//Get the Timestamp
const date1_time_stamp = start.getTime();
const date2_time_stamp = end.getTime();
let calc;
//Check which timestamp is greater
if (date1_time_stamp > date2_time_stamp) {
calc = new Date(date1_time_stamp - date2_time_stamp);
} else {
calc = new Date(date2_time_stamp - date1_time_stamp);
}
//retrieve the date, month and year
const calcFormatTmp =
calc.getDate() + "-" + (calc.getMonth() + 1) + "-" + calc.getFullYear();
//Convert to an array and store
const calcFormat = calcFormatTmp.split("-");
//Subtract each member of our array from the default date
const days_passed = Number(Math.abs(Number(calcFormat[0])) - 1);
const months_passed = Number(Math.abs(Number(calcFormat[1])) - 1);
const years_passed = Number(Math.abs(Number(calcFormat[2])) - 1970);
//Set up custom text
const yrsTxt = "ปี";
const mnthsTxt = "เดือน";
const daysTxt = "วัน";
//display result with custom text
const result =
(years_passed > 0 && (months_passed > 0 || days_passed > 0)
? years_passed + " " + yrsTxt + ", "
: "") +
(years_passed > 0 && months_passed == 0 && days_passed == 0
? years_passed + " " + yrsTxt + " "
: "") +
(months_passed > 0 && days_passed > 0
? months_passed + " " + mnthsTxt + ", "
: "") +
(months_passed > 0 && days_passed == 0
? months_passed + " " + mnthsTxt + " "
: "") +
(days_passed > 0 ? days_passed + " " + daysTxt : "");
return result.trim();
}
return "";
}
return {
calAge,
date2Thai,
@ -886,6 +947,7 @@ export const useCounterMixin = defineStore("mixin", () => {
typeChangeName,
statusLeave,
modalWarning,
calculateDurationYmd,
// common dialog
dialogConfirm,
dialogRemove,