แก้ไขการแสดงผลการลาในส่วน
This commit is contained in:
parent
b670ae3733
commit
1d624cd854
8 changed files with 233 additions and 13 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue