2026-04-20 18:20:20 +07:00
|
|
|
/**
|
|
|
|
|
* คำนวณอายุงานจากจำนวนวันรวม
|
2026-05-12 17:24:15 +07:00
|
|
|
* ใช้สูตรเดียวกับ Stored Procedure GetProfileSalaryPosition
|
2026-04-20 18:20:20 +07:00
|
|
|
* @param totalDays จำนวนวันรวม
|
|
|
|
|
* @returns { year, month, day } ปี เดือน วัน
|
|
|
|
|
*/
|
|
|
|
|
export function calculateTenure(totalDays: number) {
|
2026-05-12 17:24:15 +07:00
|
|
|
// Match stored procedure formula:
|
|
|
|
|
// days_diff / 365.2524 AS Years
|
|
|
|
|
// (days_diff / 30.4375) % 12 AS Months
|
|
|
|
|
// days_diff % 30.4375 AS Days
|
2026-04-20 18:20:20 +07:00
|
|
|
|
2026-05-12 17:24:15 +07:00
|
|
|
const year = Math.floor(totalDays / 365.2524);
|
|
|
|
|
const month = Math.floor((totalDays / 30.4375) % 12);
|
|
|
|
|
const day = Math.floor(totalDays % 30.4375);
|
2026-04-20 18:20:20 +07:00
|
|
|
|
|
|
|
|
return { year, month, day };
|
|
|
|
|
}
|