hrms-api-org/src/utils/tenure.ts

19 lines
725 B
TypeScript
Raw Normal View History

/**
*
* Stored Procedure GetProfileSalaryPosition
* @param totalDays
* @returns { year, month, day }
*/
export function calculateTenure(totalDays: number) {
// Match stored procedure formula:
// days_diff / 365.2524 AS Years
// (days_diff / 30.4375) % 12 AS Months
// days_diff % 30.4375 AS Days
const year = Math.floor(totalDays / 365.2524);
const month = Math.floor((totalDays / 30.4375) % 12);
const day = Math.floor(totalDays % 30.4375);
return { year, month, day };
}