fixed calculate tenure (สูตรคำนวนอายุราชการจาก diff date)
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m6s

This commit is contained in:
Warunee Tamkoo 2026-04-20 18:20:20 +07:00
parent 5e52206987
commit 7e3982a96d
3 changed files with 85 additions and 57 deletions

23
src/utils/tenure.ts Normal file
View 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 };
}