fixed calculate tenure (สูตรคำนวนอายุราชการจาก diff date)
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m6s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m6s
This commit is contained in:
parent
5e52206987
commit
7e3982a96d
3 changed files with 85 additions and 57 deletions
23
src/utils/tenure.ts
Normal file
23
src/utils/tenure.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* คำนวณอายุงานจากจำนวนวันรวม
|
||||
* @param totalDays จำนวนวันรวม
|
||||
* @returns { year, month, day } ปี เดือน วัน
|
||||
*/
|
||||
export function calculateTenure(totalDays: number) {
|
||||
// 1. แปลงเป็น year เต็ม
|
||||
const year = Math.floor(totalDays / 365.2524);
|
||||
|
||||
// 2. วันที่เหลือหลังหัก year ออก
|
||||
const remainAfterYear = totalDays - year * 365.2524;
|
||||
|
||||
// 3. แปลงเป็น month เต็ม
|
||||
const month = Math.floor(remainAfterYear / 30.4375);
|
||||
|
||||
// 4. วันที่เหลือหลังหัก month ออก
|
||||
const remainAfterMonth = remainAfterYear - month * 30.4375;
|
||||
|
||||
// 5. ปัดลง เฉพาะวัน
|
||||
const day = Math.floor(remainAfterMonth);
|
||||
|
||||
return { year, month, day };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue